SharmaAmit1818 commited on
Commit
072f63a
·
verified ·
1 Parent(s): 610bb32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -12,6 +12,7 @@ def process_csv(file):
12
  try:
13
  # Read the CSV file
14
  df = pd.read_csv(file.name) # Use file.name to get the file path
 
15
  # Ensure the CSV has a 'text' column
16
  if 'text' not in df.columns:
17
  return "Error: The CSV file must contain a 'text' column."
@@ -25,17 +26,21 @@ def process_csv(file):
25
 
26
  # Get predicted classes
27
  _, predicted_classes = torch.max(outputs.logits, dim=1)
 
 
28
  df['predicted_class'] = predicted_classes.numpy()
29
 
30
  # Return the processed DataFrame as a CSV string
31
- return df.to_csv(index=False)
 
 
32
 
33
  except Exception as e:
34
  return f"Error: {str(e)}"
35
 
36
  # Create the Gradio interface
37
  input_csv = gr.File(label="Upload CSV File")
38
- output_csv = gr.Textbox(label="Output")
39
 
40
  demo = gr.Interface(
41
  fn=process_csv,
 
12
  try:
13
  # Read the CSV file
14
  df = pd.read_csv(file.name) # Use file.name to get the file path
15
+
16
  # Ensure the CSV has a 'text' column
17
  if 'text' not in df.columns:
18
  return "Error: The CSV file must contain a 'text' column."
 
26
 
27
  # Get predicted classes
28
  _, predicted_classes = torch.max(outputs.logits, dim=1)
29
+
30
+ # Add predicted classes to the DataFrame
31
  df['predicted_class'] = predicted_classes.numpy()
32
 
33
  # Return the processed DataFrame as a CSV string
34
+ output_csv = df.to_csv(index=False)
35
+
36
+ return output_csv
37
 
38
  except Exception as e:
39
  return f"Error: {str(e)}"
40
 
41
  # Create the Gradio interface
42
  input_csv = gr.File(label="Upload CSV File")
43
+ output_csv = gr.File(label="Download Processed CSV")
44
 
45
  demo = gr.Interface(
46
  fn=process_csv,