Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -202,10 +202,22 @@ def generate_text(df, country, theme):
|
|
202 |
#for column in df.columns:
|
203 |
# if column != 'Country':
|
204 |
# df[column] = df[column].apply(lambda x: f"{x:.6f}%")
|
205 |
-
row = df[df['Country'] == country].iloc[0]
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
# Convert the row to a string format for prompt
|
208 |
-
|
|
|
|
|
209 |
|
210 |
simple_prompt = f"""
|
211 |
Here is the data for {theme} in {country}:
|
@@ -217,19 +229,20 @@ def generate_text(df, country, theme):
|
|
217 |
prompt = f"""
|
218 |
Here is an example of how to describe adverse growth data for a given country:
|
219 |
Country: Australia
|
220 |
-
Adverse 2020: -0.
|
221 |
-
Adverse 2021: -1.
|
222 |
-
Adverse 2022: -1.
|
223 |
-
|
224 |
-
The topic is GDP.
|
225 |
|
226 |
Description:
|
227 |
-
In the adverse scenario, the growth for GDP in Australia
|
228 |
|
229 |
Now, using the following data for {theme} in {country}, describe the adverse growth:
|
230 |
{row_str}
|
231 |
The topic is {theme}.
|
232 |
-
|
|
|
|
|
233 |
"""
|
234 |
|
235 |
|
|
|
202 |
#for column in df.columns:
|
203 |
# if column != 'Country':
|
204 |
# df[column] = df[column].apply(lambda x: f"{x:.6f}%")
|
205 |
+
#row = df[df['Country'] == country].iloc[0]
|
206 |
+
def format_row_for_prompt(row):
|
207 |
+
# Create a formatted string with colons and percentages
|
208 |
+
formatted_row = []
|
209 |
+
for col, value in row.items():
|
210 |
+
if col != 'Country': # Exclude 'Country' or format differently if needed
|
211 |
+
if isinstance(value, (int, float)): # Add percentage sign for numeric values
|
212 |
+
value_str = f"{value:.6f}%"
|
213 |
+
else:
|
214 |
+
value_str = str(value)
|
215 |
+
formatted_row.append(f"{col}: {value_str}")
|
216 |
+
return "\n".join(formatted_row)
|
217 |
# Convert the row to a string format for prompt
|
218 |
+
row = df[df['Country'] == country].iloc[0]
|
219 |
+
row_str = format_row_for_prompt(row)
|
220 |
+
#row_str = row.to_string(index=True)
|
221 |
|
222 |
simple_prompt = f"""
|
223 |
Here is the data for {theme} in {country}:
|
|
|
229 |
prompt = f"""
|
230 |
Here is an example of how to describe adverse growth data for a given country:
|
231 |
Country: Australia
|
232 |
+
Adverse 2020: -0.43%
|
233 |
+
Adverse 2021: -1.99%
|
234 |
+
Adverse 2022: -1.20%
|
235 |
+
Cumulative: -3.57%
|
|
|
236 |
|
237 |
Description:
|
238 |
+
In the adverse scenario, the growth for GDP in Australia was -0.43% in 2020, worsened further to -1.99% in 2021, and slightly improved to -1.20% in 2022. The cumulative adverse growth is -3.57%.
|
239 |
|
240 |
Now, using the following data for {theme} in {country}, describe the adverse growth:
|
241 |
{row_str}
|
242 |
The topic is {theme}.
|
243 |
+
- Highlight changes between the years.
|
244 |
+
- Accurately describe whether the values increase or decrease.
|
245 |
+
- Include the cumulative result, and reflect the data as it appears.
|
246 |
"""
|
247 |
|
248 |
|