Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -80,19 +80,16 @@ def determine_mood(data: dict) -> str:
|
|
80 |
def create_narrative(city: str, data: dict) -> str:
|
81 |
return f"In {city}, the weather is {data['weather_condition']} with a temperature of {data['temperature']}°C."
|
82 |
|
83 |
-
# Function to generate a story using OpenAI
|
84 |
def generate_story_with_ai(narrative: str, mood: str) -> str:
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
model="gpt-3.5-turbo",
|
91 |
-
messages=messages,
|
92 |
-
max_tokens=150,
|
93 |
temperature=0.7
|
94 |
)
|
95 |
-
return response
|
96 |
|
97 |
# Function to generate simulated environmental data
|
98 |
def generate_simulated_data(city: str) -> dict:
|
@@ -100,13 +97,13 @@ def generate_simulated_data(city: str) -> dict:
|
|
100 |
f"Generate simulated environmental data for {city} in JSON format with fields:\n"
|
101 |
f"1. AQI\n2. Deforestation Rate\n3. Water Quality\n4. Biodiversity Impact"
|
102 |
)
|
103 |
-
response = openai.
|
104 |
-
|
105 |
-
|
106 |
max_tokens=100,
|
107 |
temperature=0.8
|
108 |
)
|
109 |
-
response_content = response
|
110 |
try:
|
111 |
return eval(response_content)
|
112 |
except Exception as e:
|
|
|
80 |
def create_narrative(city: str, data: dict) -> str:
|
81 |
return f"In {city}, the weather is {data['weather_condition']} with a temperature of {data['temperature']}°C."
|
82 |
|
83 |
+
# Function to generate a story using OpenAI Completion API
|
84 |
def generate_story_with_ai(narrative: str, mood: str) -> str:
|
85 |
+
prompt = f"{narrative} The mood is '{mood}'. Write a short story about how the environment feels in 50 words."
|
86 |
+
response = openai.Completion.create(
|
87 |
+
engine="text-davinci-003",
|
88 |
+
prompt=prompt,
|
89 |
+
max_tokens=50,
|
|
|
|
|
|
|
90 |
temperature=0.7
|
91 |
)
|
92 |
+
return response.choices[0].text.strip()
|
93 |
|
94 |
# Function to generate simulated environmental data
|
95 |
def generate_simulated_data(city: str) -> dict:
|
|
|
97 |
f"Generate simulated environmental data for {city} in JSON format with fields:\n"
|
98 |
f"1. AQI\n2. Deforestation Rate\n3. Water Quality\n4. Biodiversity Impact"
|
99 |
)
|
100 |
+
response = openai.Completion.create(
|
101 |
+
engine="text-davinci-003",
|
102 |
+
prompt=prompt,
|
103 |
max_tokens=100,
|
104 |
temperature=0.8
|
105 |
)
|
106 |
+
response_content = response.choices[0].text.strip()
|
107 |
try:
|
108 |
return eval(response_content)
|
109 |
except Exception as e:
|