tahamueed23 commited on
Commit
f0abce9
·
verified ·
1 Parent(s): cd458ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -90,13 +90,18 @@ def analyze_sentiment(text, lang_hint):
90
  explanation = sentiment_with_tips(sentiment)
91
 
92
  # Save to CSV
93
- df = pd.read_csv(SAVE_FILE)
 
 
 
 
94
  new_row = pd.DataFrame([[text, lang, sentiment, score]],
95
  columns=["Sentence", "Language", "Sentiment", "Confidence"])
96
  df = pd.concat([df, new_row], ignore_index=True)
97
- df.to_csv(SAVE_FILE, index=False)
98
 
99
- return f"{sentiment}", f"{score}", f"{explanation}", SAVE_FILE
 
 
100
 
101
  # -----------------------------
102
  # Gradio UI
 
90
  explanation = sentiment_with_tips(sentiment)
91
 
92
  # Save to CSV
93
+ try:
94
+ df = pd.read_csv(SAVE_FILE, encoding="utf-8-sig")
95
+ except:
96
+ df = pd.DataFrame(columns=["Sentence", "Language", "Sentiment", "Confidence"])
97
+
98
  new_row = pd.DataFrame([[text, lang, sentiment, score]],
99
  columns=["Sentence", "Language", "Sentiment", "Confidence"])
100
  df = pd.concat([df, new_row], ignore_index=True)
 
101
 
102
+ # Save with proper encoding for Urdu
103
+ df.to_csv(SAVE_FILE, index=False, encoding="utf-8-sig")
104
+
105
 
106
  # -----------------------------
107
  # Gradio UI