apapis added
This commit is contained in:
@@ -21,6 +21,7 @@ import requests
|
||||
import os
|
||||
from PyPDF2 import PdfReader
|
||||
from scripts.transcriber import transcribe_media,group_words_into_sentences # Import the transcribe_media function
|
||||
from scripts.generate_summary import general_summary,custom_summary
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
API_KEY = os.getenv("API_KEY_ACCESS")
|
||||
@@ -70,7 +71,17 @@ class ChatResp(BaseModel): # Added BaseModel inheritance
|
||||
error: Optional[str] = None
|
||||
class TranscriptResponse(BaseModel):
|
||||
transcript: dict # Changed type hint for transcript to a dictionary
|
||||
|
||||
|
||||
|
||||
class GeneralSummaryRequest(BaseModel):
|
||||
transcript: Optional[str] = None
|
||||
|
||||
class TemplateSummaryRequest(BaseModel):
|
||||
transcript: Optional[str] = None
|
||||
template: Optional[str] = None
|
||||
|
||||
|
||||
@app.post("/microdot-ai/transcribe")
|
||||
async def chat_endpoint(
|
||||
request: TranscribeRequest,
|
||||
@@ -101,7 +112,57 @@ async def chat_endpoint(
|
||||
)
|
||||
|
||||
|
||||
@app.post("/microdot-ai/general-summary")
|
||||
async def general_summary_endpoint(
|
||||
request: GeneralSummaryRequest,
|
||||
api_key: str = Depends(get_api_key)
|
||||
):
|
||||
try:
|
||||
if not request.transcript:
|
||||
raise HTTPException(status_code=400, detail="Transcript is required.")
|
||||
|
||||
response = general_summary(json.loads(request.transcript))
|
||||
|
||||
return TranscriptResponse(
|
||||
transcript=response
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing general summary request: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Error processing general summary request: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@app.post("/microdot-ai/template-summary")
|
||||
async def template_summary_endpoint( # Corrected function name to avoid conflict
|
||||
request: TemplateSummaryRequest,
|
||||
api_key: str = Depends(get_api_key)
|
||||
):
|
||||
try:
|
||||
if not request.transcript:
|
||||
raise HTTPException(status_code=400, detail="Transcript is required.")
|
||||
|
||||
if not request.template:
|
||||
raise HTTPException(status_code=400, detail="Template is required.")
|
||||
|
||||
transcript = json.loads(request.transcript)
|
||||
template = json.loads(request.template) # Removed the check for missing template as it's now required
|
||||
response = custom_summary(template, transcript)
|
||||
|
||||
return TranscriptResponse(
|
||||
transcript=response
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing template summary request: {str(e)}") # Updated print statement for clarity
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Error processing template summary request: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""Initialize required components on startup"""
|
||||
|
||||
Reference in New Issue
Block a user