Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,22 +17,19 @@ def analyze_csv(file_path):
|
|
| 17 |
results = df['text'].apply(lambda x: sentiment_pipeline(x)[0])
|
| 18 |
df['sentiment'] = results.apply(lambda r: r['label'])
|
| 19 |
df['score'] = results.apply(lambda r: r['score'])
|
| 20 |
-
|
| 21 |
-
# Return the DataFrame as a CSV string
|
| 22 |
-
return df.to_csv(index=False)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return
|
| 28 |
|
| 29 |
# Define the Gradio interface
|
| 30 |
iface = gr.Interface(
|
| 31 |
-
fn=
|
| 32 |
inputs=gr.File(label="Upload CSV File", file_count="single", type="filepath"),
|
| 33 |
-
outputs=gr.
|
| 34 |
title="CSV Sentiment Analysis App",
|
| 35 |
-
description="Upload a CSV file with a 'text' column. The app will run sentiment analysis on each row and return
|
| 36 |
)
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
|
|
|
| 17 |
results = df['text'].apply(lambda x: sentiment_pipeline(x)[0])
|
| 18 |
df['sentiment'] = results.apply(lambda r: r['label'])
|
| 19 |
df['score'] = results.apply(lambda r: r['score'])
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Save output to a new CSV file
|
| 22 |
+
output_csv_path = "output.csv"
|
| 23 |
+
df.to_csv(output_csv_path, index=False)
|
| 24 |
+
return output_csv_path # Return path to the new CSV
|
| 25 |
|
| 26 |
# Define the Gradio interface
|
| 27 |
iface = gr.Interface(
|
| 28 |
+
fn=analyze_csv,
|
| 29 |
inputs=gr.File(label="Upload CSV File", file_count="single", type="filepath"),
|
| 30 |
+
outputs=gr.File(label="Download CSV File"),
|
| 31 |
title="CSV Sentiment Analysis App",
|
| 32 |
+
description="Upload a CSV file with a 'text' column. The app will run sentiment analysis on each row and return a downloadable CSV with sentiment labels and scores."
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|