Update app.py
Browse files
app.py
CHANGED
@@ -7,82 +7,79 @@ from fastapi.responses import HTMLResponse
|
|
7 |
from gradio_client import Client
|
8 |
import uvicorn
|
9 |
|
10 |
-
|
11 |
app = FastAPI(title="Meeting Summarizer API")
|
12 |
|
13 |
-
|
14 |
# Replace this with your actual deployed HF space/model if needed
|
15 |
HF_MODEL_SPACE = "Ravishankarsharma/voice2text-summarizer"
|
16 |
|
17 |
-
|
18 |
# Public demo audio (replace if you want your own)
|
19 |
DEM0_AUDIO_URL = "https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/0001.flac"
|
20 |
|
21 |
-
|
22 |
# Initialize HF client
|
23 |
try:
|
24 |
-
client = Client(HF_MODEL_SPACE)
|
25 |
except Exception as e:
|
26 |
-
print("⚠️ Client initialization failed:", e)
|
27 |
-
client = None
|
28 |
-
|
29 |
-
|
30 |
|
31 |
|
32 |
@app.get("/", response_class=HTMLResponse)
|
33 |
async def home():
|
34 |
-
return """
|
35 |
-
<html><body>
|
36 |
-
<h2>Meeting Summarizer API</h2>
|
37 |
-
<p>➡️ Call <a href='/summarize'>/summarize</a> to get meeting summary</p>
|
38 |
-
<p>➡️ Swagger docs: <a href='/docs'>/docs</a></p>
|
39 |
-
</body></html>
|
40 |
-
"""
|
41 |
-
|
42 |
-
|
43 |
|
44 |
|
45 |
@app.get("/summarize")
|
46 |
async def summarize_meeting():
|
47 |
-
if not client:
|
48 |
-
raise HTTPException(status_code=500, detail="❌ Hugging Face client not initialized")
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
suffix = ".flac" if meeting_url.endswith('.flac') else os.path.splitext(meeting_url)[1] or ".wav"
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
tmp.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
#
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
7 |
from gradio_client import Client
|
8 |
import uvicorn
|
9 |
|
|
|
10 |
app = FastAPI(title="Meeting Summarizer API")
|
11 |
|
|
|
12 |
# Replace this with your actual deployed HF space/model if needed
|
13 |
HF_MODEL_SPACE = "Ravishankarsharma/voice2text-summarizer"
|
14 |
|
|
|
15 |
# Public demo audio (replace if you want your own)
|
16 |
DEM0_AUDIO_URL = "https://huggingface.co/datasets/Narsil/asr_dummy/resolve/main/0001.flac"
|
17 |
|
|
|
18 |
# Initialize HF client
|
19 |
try:
|
20 |
+
client = Client(HF_MODEL_SPACE)
|
21 |
except Exception as e:
|
22 |
+
print("⚠️ Client initialization failed:", e)
|
23 |
+
client = None
|
|
|
|
|
24 |
|
25 |
|
26 |
@app.get("/", response_class=HTMLResponse)
|
27 |
async def home():
|
28 |
+
return """
|
29 |
+
<html><body>
|
30 |
+
<h2>Meeting Summarizer API</h2>
|
31 |
+
<p>➡️ Call <a href='/summarize'>/summarize</a> to get meeting summary</p>
|
32 |
+
<p>➡️ Swagger docs: <a href='/docs'>/docs</a></p>
|
33 |
+
</body></html>
|
34 |
+
"""
|
|
|
|
|
35 |
|
36 |
|
37 |
@app.get("/summarize")
|
38 |
async def summarize_meeting():
|
39 |
+
if not client:
|
40 |
+
raise HTTPException(status_code=500, detail="❌ Hugging Face client not initialized")
|
41 |
+
|
42 |
+
try:
|
43 |
+
meeting_url = DEM0_AUDIO_URL
|
44 |
+
|
45 |
+
# Download audio
|
46 |
+
response = requests.get(meeting_url, stream=True, timeout=30)
|
47 |
+
if response.status_code != 200:
|
48 |
+
raise HTTPException(
|
49 |
+
status_code=400,
|
50 |
+
detail=f"Failed to fetch meeting audio (status {response.status_code})"
|
51 |
+
)
|
52 |
+
|
53 |
+
suffix = ".flac" if meeting_url.endswith('.flac') else os.path.splitext(meeting_url)[1] or ".wav"
|
54 |
+
|
55 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
56 |
+
for chunk in response.iter_content(chunk_size=8192):
|
57 |
+
if chunk:
|
58 |
+
tmp.write(chunk)
|
59 |
+
tmp_path = tmp.name
|
60 |
+
|
61 |
+
# Call your HF model. The predict input depends on how your space expects input.
|
62 |
+
# If your space expects a file, use handle_file(tmp_path) instead. Here we try both common ways.
|
63 |
+
try:
|
64 |
+
# First try: send file path (many gradio-based spaces accept this)
|
65 |
+
result = client.predict(tmp_path, api_name="/predict")
|
66 |
+
except Exception:
|
67 |
+
# Fallback: send the raw bytes
|
68 |
+
with open(tmp_path, "rb") as fd:
|
69 |
+
data = fd.read()
|
70 |
+
result = client.predict(data, api_name="/predict")
|
71 |
+
|
72 |
+
# Clean up
|
73 |
+
try:
|
74 |
+
os.remove(tmp_path)
|
75 |
+
except Exception:
|
76 |
+
pass
|
77 |
+
|
78 |
+
return result
|
79 |
+
|
80 |
+
except Exception as e:
|
81 |
+
raise HTTPException(status_code=500, detail=f"❌ Error summarizing meeting: {e}")
|
82 |
+
|
83 |
+
|
84 |
+
if __name__ == "__main__":
|
85 |
+
uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True)
|