Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,13 @@ def analyze_file(file):
|
|
| 6 |
if file is None:
|
| 7 |
return None, None
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Auto-detect the text column
|
| 12 |
text_col = None
|
|
@@ -18,21 +24,25 @@ def analyze_file(file):
|
|
| 18 |
if text_col is None:
|
| 19 |
text_col = df.columns[0] # fallback to first column
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
results.append(cat)
|
| 27 |
-
keys.append(key)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
-
|
| 33 |
-
df.to_excel(output, index=False)
|
| 34 |
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
demo = gr.Interface(
|
|
|
|
| 6 |
if file is None:
|
| 7 |
return None, None
|
| 8 |
|
| 9 |
+
try:
|
| 10 |
+
df = pd.read_excel(file.name)
|
| 11 |
+
except Exception as e:
|
| 12 |
+
raise gr.Error(f"Failed to read Excel file: {str(e)}")
|
| 13 |
+
|
| 14 |
+
# Show column names in error so we can debug
|
| 15 |
+
col_names = df.columns.tolist()
|
| 16 |
|
| 17 |
# Auto-detect the text column
|
| 18 |
text_col = None
|
|
|
|
| 24 |
if text_col is None:
|
| 25 |
text_col = df.columns[0] # fallback to first column
|
| 26 |
|
| 27 |
+
try:
|
| 28 |
+
results = []
|
| 29 |
+
keys = []
|
| 30 |
+
|
| 31 |
+
for text in df[text_col]:
|
| 32 |
+
cat, key = detect_discrimination(str(text))
|
| 33 |
+
results.append(cat)
|
| 34 |
+
keys.append(key)
|
| 35 |
|
| 36 |
+
df["Discrimination_Type"] = results
|
| 37 |
+
df["Detected_Keywords"] = keys
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
output = "results.xlsx"
|
| 40 |
+
df.to_excel(output, index=False)
|
| 41 |
|
| 42 |
+
return df, output
|
|
|
|
| 43 |
|
| 44 |
+
except Exception as e:
|
| 45 |
+
raise gr.Error(f"Column names found: {col_names}. Error: {str(e)}")
|
| 46 |
|
| 47 |
|
| 48 |
demo = gr.Interface(
|