-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor project structure, add Docker support, and improve environme…
…nt variable management.
- Loading branch information
Showing
22 changed files
with
149 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
.env | ||
# Python bytecode files | ||
__pycache__/ | ||
*.pyc | ||
*.pyo | ||
|
||
# Virtual environment | ||
venv/ | ||
__pycache__/ | ||
env/ | ||
|
||
# .env file (contains sensitive API keys) | ||
.env | ||
|
||
# Docker-related files | ||
docker-compose.override.yml | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
from fastapi import FastAPI, HTTPException, Request | ||
from fastapi.responses import JSONResponse, HTMLResponse | ||
from fastapi.staticfiles import StaticFiles | ||
from fastapi.templating import Jinja2Templates | ||
from dotenv import load_dotenv | ||
from app.services.youtube_service import YouTubeService | ||
from app.services.genai_service import GenaiService | ||
|
||
# Load environment variables | ||
load_dotenv() | ||
|
||
# FastAPI app initialization | ||
app = FastAPI() | ||
|
||
# Mount static files and templates | ||
app.mount("/static", StaticFiles(directory="static"), name="static") | ||
templates = Jinja2Templates(directory="app/templates") | ||
|
||
# Load API keys from .env | ||
api_key = os.getenv("ASSEMBLYAI_API_KEY") | ||
genaiApiKey = os.getenv("GENAI_API_KEY") | ||
modelName = "multi-qa-mpnet-base-dot-v1" | ||
|
||
class ProcessRequest(BaseModel): | ||
action: str | ||
input: str | ||
|
||
@app.post("/process") | ||
async def process_request(request: ProcessRequest): | ||
action = request.action | ||
input_text = request.input | ||
|
||
if action == "transcribe": | ||
yt_service = YouTubeService(api_key, input_text) | ||
yt_service.download_video() | ||
transcript_text = yt_service.transcribe_video("video.m4a") | ||
if not transcript_text: | ||
raise HTTPException(status_code=500, detail="Transcription failed.") | ||
|
||
genai_service = GenaiService(modelName, genaiApiKey) | ||
summary_text = genai_service.getSummary(transcript_text) | ||
return JSONResponse(content={"status": "success", "summary": summary_text}) | ||
|
||
elif action == "ask": | ||
genai_service = GenaiService(modelName, genaiApiKey) | ||
answer_text = genai_service.getAnswer(input_text, [input_text]) | ||
return JSONResponse(content={"status": "success", "answer": answer_text}) | ||
|
||
else: | ||
raise HTTPException(status_code=400, detail="Invalid action.") | ||
|
||
@app.get("/", response_class=HTMLResponse) | ||
async def read_root(request: Request): | ||
return templates.TemplateResponse("index.html", {"request": request}) | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import google.generativeai as genai | ||
from app.services.qa_service import QAService | ||
from sentence_transformers import SentenceTransformer | ||
|
||
class GenaiService: | ||
def __init__(self, model_name, genai_api_key): | ||
self.model = SentenceTransformer(model_name) | ||
genai.configure(api_key=genai_api_key) | ||
self.genai_model = genai.GenerativeModel(model_name="gemini-1.5-flash") | ||
|
||
def get_summary(self, transcription_text): | ||
if not transcription_text: | ||
return "No transcription text provided." | ||
input_user = (f"This document contains a transcription of the video's audio. Please provide a professionally crafted summary based on the transcript. Transcription: {transcription_text}") | ||
response = self.genai_model.generate_content(input_user) | ||
return response.text | ||
|
||
def get_answer(self, query, local_data): | ||
qa_service = QAService(self.model) | ||
answer = qa_service.answer_query(query, local_data) | ||
input_user = f"For this question, provide a direct and accurate answer. {query}\n\n{answer}" | ||
response = self.genai_model.generate_content(input_user) | ||
return response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.