norhan12 commited on
Commit
a9a21fe
·
verified ·
1 Parent(s): 93c279b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -26
app.py CHANGED
@@ -1,10 +1,9 @@
1
  import logging
2
  import os
3
  from fastapi import FastAPI, HTTPException
4
- from fastapi.responses import FileResponse # --- NEW IMPORT ---
5
  from pydantic import BaseModel, HttpUrl
6
- from typing import List, Dict
7
- from concurrent.futures import ThreadPoolExecutor
8
  from process_interview import process_interview
9
 
10
  logging.basicConfig(
@@ -14,29 +13,26 @@ logger = logging.getLogger(__name__)
14
 
15
  app = FastAPI(
16
  title="EvalBot API",
17
- description="API to analyze audio interviews.",
18
  version="1.0.0"
19
  )
20
 
21
- # --- The directory where output files are stored ---
22
  OUTPUT_DIR = "./processed_audio"
23
-
24
 
25
  class AudioItem(BaseModel):
26
  url: HttpUrl
27
  user_id: str
28
 
29
- class AnalysisRequest(BaseModel):
30
- audio_items: List[AudioItem]
31
-
32
  def process_item_wrapper(item: AudioItem) -> Dict:
33
  try:
34
  logger.info(f"Starting analysis for user '{item.user_id}' with URL: {item.url}")
35
  result = process_interview(str(item.url))
36
- # --- MODIFICATION: Return just the filename, not the full path ---
37
- if result and "pdf_path" in result:
38
  result["pdf_filename"] = os.path.basename(result["pdf_path"])
39
- if result and "json_path" in result:
40
  result["json_filename"] = os.path.basename(result["json_path"])
41
 
42
  return {
@@ -58,21 +54,16 @@ def process_item_wrapper(item: AudioItem) -> Dict:
58
  def health_check():
59
  return {"status": "ok"}
60
 
61
- @app.post("/analyze", summary="Analyze a list of audio URLs")
62
- def analyze_audios(request: AnalysisRequest):
63
- if not request.audio_items:
64
- raise HTTPException(status_code=400, detail="No audio items provided.")
65
- logger.info(f"Received request to analyze {len(request.audio_items)} audio items.")
66
- results = []
67
- with ThreadPoolExecutor(max_workers=5) as executor:
68
- futures = [executor.submit(process_item_wrapper, item) for item in request.audio_items]
69
- for future in futures:
70
- results.append(future.result())
71
- logger.info("Finished processing all items.")
72
- return {"analysis_results": results}
73
-
74
 
75
- # --- NEW ENDPOINT TO DOWNLOAD OUTPUT FILES ---
76
  @app.get("/outputs/{file_name}", summary="Download an output file")
77
  def get_output_file(file_name: str):
78
  """
 
1
  import logging
2
  import os
3
  from fastapi import FastAPI, HTTPException
4
+ from fastapi.responses import FileResponse
5
  from pydantic import BaseModel, HttpUrl
6
+ from typing import Dict
 
7
  from process_interview import process_interview
8
 
9
  logging.basicConfig(
 
13
 
14
  app = FastAPI(
15
  title="EvalBot API",
16
+ description="API to analyze a single audio interview URL.",
17
  version="1.0.0"
18
  )
19
 
20
+ # Directory where output files are stored
21
  OUTPUT_DIR = "./processed_audio"
22
+ os.makedirs(OUTPUT_DIR, exist_ok=True)
23
 
24
  class AudioItem(BaseModel):
25
  url: HttpUrl
26
  user_id: str
27
 
 
 
 
28
  def process_item_wrapper(item: AudioItem) -> Dict:
29
  try:
30
  logger.info(f"Starting analysis for user '{item.user_id}' with URL: {item.url}")
31
  result = process_interview(str(item.url))
32
+ # Return just the filename, not the full path
33
+ if result and "pdf_path" in result and result["pdf_path"]:
34
  result["pdf_filename"] = os.path.basename(result["pdf_path"])
35
+ if result and "json_path" in result and result["json_path"]:
36
  result["json_filename"] = os.path.basename(result["json_path"])
37
 
38
  return {
 
54
  def health_check():
55
  return {"status": "ok"}
56
 
57
+ @app.post("/analyze", summary="Analyze a single audio URL")
58
+ def analyze_audio(request: AudioItem):
59
+ """
60
+ Analyze a single audio URL and return analysis results.
61
+ """
62
+ logger.info(f"Received request to analyze audio for user '{request.user_id}' with URL: {request.url}")
63
+ result = process_item_wrapper(request)
64
+ logger.info(f"Finished processing audio for user '{request.user_id}'")
65
+ return {"analysis_result": result}
 
 
 
 
66
 
 
67
  @app.get("/outputs/{file_name}", summary="Download an output file")
68
  def get_output_file(file_name: str):
69
  """