Zoro-147 commited on
Commit
6c3e4b6
·
verified ·
1 Parent(s): 3ff63af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -21,35 +21,25 @@ def analyze_sentiment(text: str) -> dict:
21
  async def handle_mcp_request(data: dict):
22
  """
23
  MCP-compatible endpoint
24
- Expected input: {"parameters": {"text": "your text here"}}
25
  """
26
  try:
27
  text = data.get("parameters", {}).get("text", "")
28
  if not text:
29
  raise HTTPException(status_code=400, detail="Missing 'text' parameter")
30
 
31
- result = analyze_sentiment(text)
32
  return {
33
  "jsonrpc": "2.0",
34
- "result": result,
35
  "id": "sentiment-response"
36
  }
37
  except Exception as e:
38
  raise HTTPException(status_code=500, detail=str(e))
39
 
40
- from fastapi.staticfiles import StaticFiles
41
- import gradio as gr
42
-
43
- # Mount Gradio interface at /ui
44
- app.mount("/ui", gr.routes.App.create_app(demo))
45
-
46
- # Create Gradio interface (same as original)
47
- demo = gr.Interface(
48
- fn=lambda text: analyze_sentiment(text),
49
- inputs=gr.Textbox(),
50
- outputs=gr.JSON(),
51
- title="Sentiment Analysis UI"
52
- )
53
 
54
  if __name__ == "__main__":
55
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
21
  async def handle_mcp_request(data: dict):
22
  """
23
  MCP-compatible endpoint
24
+ Format: {"parameters": {"text": "your text"}}
25
  """
26
  try:
27
  text = data.get("parameters", {}).get("text", "")
28
  if not text:
29
  raise HTTPException(status_code=400, detail="Missing 'text' parameter")
30
 
 
31
  return {
32
  "jsonrpc": "2.0",
33
+ "result": analyze_sentiment(text),
34
  "id": "sentiment-response"
35
  }
36
  except Exception as e:
37
  raise HTTPException(status_code=500, detail=str(e))
38
 
39
+ @app.get("/")
40
+ async def health_check():
41
+ """Required for Hugging Face health checks"""
42
+ return {"status": "OK"}
 
 
 
 
 
 
 
 
 
43
 
44
  if __name__ == "__main__":
45
+ uvicorn.run(app, host="0.0.0.0", port=7860) # HF uses 7860