first test with webapp
This commit is contained in:
45
.gitignore
vendored
Normal file
45
.gitignore
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
# .gitignore
|
||||
|
||||
# Python
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
__pycache__
|
||||
*.so
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
*.tar.gz
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Pip
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
23
main.py
Normal file
23
main.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import FastAPI, Request, Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from pydantic import HttpUrl
|
||||
import uvicorn
|
||||
|
||||
import services
|
||||
|
||||
app = FastAPI()
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def function(root: Request):
|
||||
return templates.TemplateResponse("index.html", {"request": root})
|
||||
|
||||
@app.post("/", response_class=HTMLResponse)
|
||||
def function(summarize: Request, url: str = Form(...)):
|
||||
summary = services.generate_summary(url)
|
||||
return templates.TemplateResponse("index.html", {"request": summarize, "summary": summary})
|
||||
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
0
requirements.txt
Normal file
0
requirements.txt
Normal file
43
services.py
Normal file
43
services.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
import pickle
|
||||
from jinja2 import Template
|
||||
|
||||
import yt_dlp
|
||||
from whisper import load_model
|
||||
from loguru import logger
|
||||
from dotenv import load_dotenv
|
||||
import tiktoken
|
||||
|
||||
from llms import LLMService
|
||||
import pipeline
|
||||
import utils
|
||||
|
||||
|
||||
logger.debug("loading env vars")
|
||||
load_dotenv(dotenv_path='./env')
|
||||
|
||||
logger.debug("initializing llm query engines")
|
||||
query_engines = {}
|
||||
for model in ["gpt35turbo", "gpt4"]:
|
||||
llm_service = LLMService(provider="azure", model=model)
|
||||
query_engine = llm_service.initialize_client_query_engine()
|
||||
query_engines[model] = query_engine
|
||||
llm_servce = None
|
||||
|
||||
logger.debug("loading stt model")
|
||||
model = load_model("large-v3", device="cpu")
|
||||
logger.debug("distributing stt model on multi-gpu setup")
|
||||
model.encoder.to("cuda:0")
|
||||
model.decoder.to("cuda:1")
|
||||
model.decoder.register_forward_pre_hook(lambda _, inputs: tuple([inputs[0].to("cuda:1"), inputs[1].to("cuda:1")] + list(inputs[2:])))
|
||||
model.decoder.register_forward_hook(lambda _, inputs, outputs: outputs.to("cuda:0"))
|
||||
|
||||
def generate_summary(url):
|
||||
path_audiofile, name_audiofile = pipeline.download_audio(url=url)
|
||||
transcript = pipeline.transcribe(model=model, audio=path_audiofile)
|
||||
subtranscripts = pipeline.divide_transcript(transcript, max_tokens=2048)
|
||||
partial_summaries = pipeline.generate_partial_summaries(subtranscripts)
|
||||
merged_summary = pipeline.generate_merged_summary(partial_summaries)
|
||||
return merged_summary
|
||||
45
templates/index.html
Normal file
45
templates/index.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css"
|
||||
crossorigin="anonymous"
|
||||
>
|
||||
<title>URL Summarizer</title>
|
||||
<style>
|
||||
body, html {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
}
|
||||
.centered-container {
|
||||
height: 100vh;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="d-flex align-items-center justify-content-center centered-container">
|
||||
<div class="container text-center">
|
||||
<h1 class="mb-4">URL Summarizer</h1>
|
||||
<form method="post" class="form-inline justify-content-center">
|
||||
<div class="form-group mx-sm-3 mb-4">
|
||||
<label for="urlInput" class="sr-only">URL</label>
|
||||
<input type="url" class="form-control" id="urlInput" name="url" placeholder="Enter URL" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary mb-2">Summarize</button>
|
||||
</form>
|
||||
|
||||
{% if summary %}
|
||||
<div class="alert alert-info mt-4" role="alert">
|
||||
{{ summary }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user