1st
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai_secret_manager
|
| 2 |
+
|
| 3 |
+
# Get API key for OpenAI
|
| 4 |
+
secrets = openai_secret_manager.get_secret("openai")
|
| 5 |
+
api_key = secrets["api_key"]
|
| 6 |
+
|
| 7 |
+
import openai
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
# Set the model
|
| 11 |
+
model = "text-davinci-002"
|
| 12 |
+
|
| 13 |
+
def air_quality_prediction(city_name):
|
| 14 |
+
if city_name:
|
| 15 |
+
# Generate a response to the prompt
|
| 16 |
+
response = openai.Completion.create(
|
| 17 |
+
engine=model,
|
| 18 |
+
prompt=f"Air Quality Prediction for {city_name} for next 7 days",
|
| 19 |
+
max_tokens=1024,
|
| 20 |
+
n=1,
|
| 21 |
+
stop=None,
|
| 22 |
+
temperature=0.7,
|
| 23 |
+
api_key=api_key
|
| 24 |
+
)
|
| 25 |
+
# Decode the response and return it
|
| 26 |
+
return response.choices[0].text
|
| 27 |
+
|
| 28 |
+
gr.Interface(air_quality_prediction, inputs="text", outputs="text").launch()
|