jatinsabari commited on
Commit
22af3f6
·
verified ·
1 Parent(s): 717d561

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -234,4 +234,29 @@ if __name__ == "__main__":
234
  server_name="0.0.0.0",
235
  server_port=7860,
236
  share=True
237
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  server_name="0.0.0.0",
235
  server_port=7860,
236
  share=True
237
+ )
238
+ app = FastAPI()
239
+
240
+ # Enable CORS so your gateway can call this
241
+ app.add_middleware(
242
+ CORSMiddleware,
243
+ allow_origins=["*"],
244
+ allow_methods=["*"],
245
+ allow_headers=["*"],
246
+ )
247
+
248
+ @app.post("/api/analyze")
249
+ async def api_analyze(audio: UploadFile = File(...)):
250
+ """API endpoint for programmatic access"""
251
+ # Save uploaded file temporarily
252
+ temp_path = f"/tmp/{audio.filename}"
253
+ with open(temp_path, "wb") as f:
254
+ f.write(await audio.read())
255
+
256
+ # Use your existing emotion detection function
257
+ result = detect_emotion(temp_path)
258
+
259
+ return result
260
+
261
+ # Mount Gradio to FastAPI (this combines both!)
262
+ app = gr.mount_gradio_app(app, demo, path="/")