VeyVey commited on
Commit
70b5cba
1 Parent(s): 272c96d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import datetime
4
+
5
+ # Load the Hugging Face model for weather prediction
6
+ model = pipeline("text-classification", model="nlptown/bert-base-multilingual-uncased-sentiment")
7
+
8
+ def predict_weather(description):
9
+ # Use the Hugging Face model to predict the weather sentiment
10
+ prediction = model(description)[0]
11
+
12
+ # Map the sentiment prediction to weather categories
13
+ if prediction['label'] == 'positive':
14
+ weather = 'Sunny'
15
+ elif prediction['label'] == 'negative':
16
+ weather = 'Rainy'
17
+ else:
18
+ weather = 'Neutral'
19
+
20
+ # Calculate tomorrow's date
21
+ tomorrow = datetime.date.today() + datetime.timedelta(days=1)
22
+
23
+ # Return the predicted weather and tomorrow's date
24
+ return weather, tomorrow
25
+
26
+ # Define the input field for the Gradio interface
27
+ description_input = gr.inputs.Textbox(label="Weather Description")
28
+
29
+ # Define the output fields for the Gradio interface
30
+ weather_output = gr.outputs.Textbox(label="Predicted Weather")
31
+ date_output = gr.outputs.Textbox(label="Tomorrow's Date")
32
+
33
+ # Create the Gradio interface
34
+ interface = gr.Interface(fn=predict_weather,
35
+ inputs=description_input,
36
+ outputs=[weather_output, date_output],
37
+ title="Tomorrow's Weather Prediction",
38
+ description="Predict tomorrow's weather based on description.")
39
+
40
+ # Launch the Gradio interface
41
+ interface.launch()