Rehan12345678 commited on
Commit
8ac4069
·
verified ·
1 Parent(s): 1655eb9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +2 -35
src/streamlit_app.py CHANGED
@@ -2,9 +2,7 @@ import os
2
  import requests
3
  from fastapi import FastAPI
4
  from pydantic import BaseModel
5
- import gradio as gr
6
 
7
- # Initialize FastAPI app
8
  app = FastAPI()
9
 
10
  # Read API key from Hugging Face Secrets
@@ -38,37 +36,6 @@ def get_weather(request: WeatherRequest):
38
  "wind_speed": data["wind"]["speed"]
39
  }
40
 
41
- @app.get("/api")
42
  def root():
43
- return {"message": "OpenWeather MCP Server is running"}
44
-
45
- # Gradio Interface
46
- def get_weather_ui(city):
47
- """Function to be called by Gradio interface."""
48
- # Note: When calling a FastAPI endpoint from within the same app,
49
- # you can treat it as a local request.
50
- response = requests.post("http://127.0.0.1:7860/weather", json={"city": city})
51
- if response.status_code == 200:
52
- data = response.json()
53
- return f"Weather in {data['city']}, {data['country']}:\n\n" \
54
- f"Temperature: {data['temperature']}°C\n" \
55
- f"Feels like: {data['feels_like']}°C\n" \
56
- f"Humidity: {data['humidity']}%\n" \
57
- f"Description: {data['weather']}\n" \
58
- f"Wind Speed: {data['wind_speed']} m/s"
59
- else:
60
- return f"Error: {response.json()}"
61
-
62
- # Create the Gradio Interface
63
- weather_ui = gr.Interface(
64
- fn=get_weather_ui,
65
- inputs=gr.Textbox(label="Enter a City"),
66
- outputs=gr.Textbox(label="Weather Information"),
67
- title="OpenWeather App",
68
- description="Get the live weather for any city using FastAPI.",
69
- # This line prevents the PermissionError
70
- allow_flagging="never"
71
- )
72
-
73
- # Mount the Gradio app to the FastAPI application at the root path
74
- app = gr.mount_gradio_app(app, weather_ui, path="/")
 
2
  import requests
3
  from fastapi import FastAPI
4
  from pydantic import BaseModel
 
5
 
 
6
  app = FastAPI()
7
 
8
  # Read API key from Hugging Face Secrets
 
36
  "wind_speed": data["wind"]["speed"]
37
  }
38
 
39
+ @app.get("/")
40
  def root():
41
+ return {"message": "OpenWeather MCP Server is running"}