Tushar14 commited on
Commit
8b2be61
·
verified ·
1 Parent(s): f90afa7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -6,7 +6,13 @@ def analyze_file(file):
6
  if file is None:
7
  return None, None
8
 
9
- df = pd.read_excel(file)
 
 
 
 
 
 
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
- results = []
22
- keys = []
 
 
 
 
 
 
23
 
24
- for text in df[text_col]:
25
- cat, key = detect_discrimination(str(text))
26
- results.append(cat)
27
- keys.append(key)
28
 
29
- df["Discrimination_Type"] = results
30
- df["Detected_Keywords"] = keys
31
 
32
- output = "results.xlsx"
33
- df.to_excel(output, index=False)
34
 
35
- return df, output
 
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(