soctopus2327 commited on
Commit
74f516c
·
verified ·
1 Parent(s): 2a07a13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -80,16 +80,19 @@ 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 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,13 +100,13 @@ 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:
 
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
+ messages = [
86
+ {"role": "system", "content": "You are a creative storyteller using characters and imagery."},
87
+ {"role": "user", "content": f"{narrative} The mood is '{mood}', write a story about how the environment feels in 50 words."}
88
+ ]
89
+ response = openai.ChatCompletion.create(
90
+ model="gpt-3.5-turbo",
91
+ messages=messages,
92
+ max_tokens=150,
93
  temperature=0.7
94
  )
95
+ return response.choices[0].message['content'].strip()
96
 
97
  # Function to generate simulated environmental data
98
  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.ChatCompletion.create(
104
+ model="gpt-3.5-turbo",
105
+ messages=[{"role": "user", "content": prompt}],
106
  max_tokens=100,
107
  temperature=0.8
108
  )
109
+ response_content = response.choices[0].message['content'].strip()
110
  try:
111
  return eval(response_content)
112
  except Exception as e: