Skip to content

Commit

Permalink
Feat: update api with props for frontend. Add on frontend validations
Browse files Browse the repository at this point in the history
Feat: update api with props for frontend. Add on frontend validations…
  • Loading branch information
alexiusstrauss authored Nov 27, 2023
2 parents 3bd9d00 + cdd6605 commit fc0292f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions backend/src/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from fastapi import FastAPI, File, UploadFile
from fastapi import FastAPI, File, Request, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse

Expand Down Expand Up @@ -28,7 +28,7 @@ async def healthcheck():


@app.post("/process-audio/", response_model=UploadResponse)
async def create_upload_file(audio_file: UploadFile = File(..., description="arquivo .mp3 ou .wav")):
async def create_upload_file(request: Request, audio_file: UploadFile = File(..., description="arquivo .mp3 ou .wav")):
lang_chain = LangChain(api_key=OPEN_AI_TOKEN)
service = DeepDive(llm_engine=lang_chain)
service.validate_api_token()
Expand All @@ -40,7 +40,7 @@ async def create_upload_file(audio_file: UploadFile = File(..., description="arq
response = service.speech_to_text(response)
response = service.summarize_text(response=response)
response = service.create_audio_from_summary(response=response)
response = service.create_link_to_summary(response=response)
response = service.create_link_to_summary(request=request, response=response)

return UploadResponse(**response)

Expand Down
1 change: 0 additions & 1 deletion backend/src/services/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ class UploadResponse(BaseModel):
file_id: str
original_context: str = None
summary_context: str = None
audio_summarize: str = None
summary_url: str = None
7 changes: 4 additions & 3 deletions backend/src/services/services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from uuid import uuid4

import speech_recognition as sr
from fastapi import UploadFile
from fastapi import Request, UploadFile
from gtts import gTTS
from pydub import AudioSegment as Asegment
from src.summarization.engines import LangChain
Expand Down Expand Up @@ -95,6 +95,7 @@ def create_audio_from_summary(self, response: dict):
print(f"Erro ao criar arquivo de áudio: {exc}")
raise

def create_link_to_summary(self, response: dict):
response["summary_url"] = f"/download/{response.get('file_id')}"
def create_link_to_summary(self, request: Request, response: dict):
base_url = str(request.base_url)
response["summary_url"] = f"{base_url}download/{response.get('file_id')}"
return response
2 changes: 1 addition & 1 deletion backend/src/settings/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
}


OPEN_AI_TOKEN = "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"
OPEN_AI_TOKEN = "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"
6 changes: 3 additions & 3 deletions backend/src/summarization/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def __init__(self, api_key: str):
self.api_key = api_key

def summarize(self, text: str) -> str:
prompt = f"Por favor, analise o seguinte texto e crie um resumo breve, \
focando nas ideias principais e informações mais relevantes. \
prompt = f"Por favor, analise o seguinte texto e crie um resumo muito breve, \
apenas com as informações mais relevantes. \
O resumo deve ser conciso, com poucas palavras, \
destacando apenas os aspectos mais importantes do texto. \
Aqui está o texto para análise: :\n\n{text}\n\n Sumário:"
Aqui está o texto para análise: \n\n{text}\n\n Sumário:"
return self.llm.predict(prompt)

def token_is_valid(self):
Expand Down

0 comments on commit fc0292f

Please sign in to comment.