its-jollu commited on
Commit
f90ae69
·
verified ·
1 Parent(s): 0f7705c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ def get_weather(city):
5
+ API_URL = "https://api-inference.huggingface.co/models/YOUR_WEATHER_MODEL"
6
+ headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_KEY"}
7
+
8
+ payload = {"inputs": city}
9
+ response = requests.post(API_URL, headers=headers, json=payload)
10
+
11
+ if response.status_code == 200:
12
+ result = response.json()
13
+ return f"Weather forecast for {city}, Pakistan: {result}"
14
+ else:
15
+ return "Error fetching weather data. Please try again."
16
+
17
+ iface = gr.Interface(
18
+ fn=get_weather,
19
+ inputs=gr.Textbox(placeholder="Enter city name in Pakistan"),
20
+ outputs="text",
21
+ title="Weather Forecast for Pakistan",
22
+ description="Enter a city name in Pakistan to get the weather forecast using a Hugging Face model."
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ iface.launch()