ManjinderUNCC commited on
Commit
6589640
1 Parent(s): 7a4f78c

Update gradio_interface.py

Browse files
Files changed (1) hide show
  1. gradio_interface.py +5 -23
gradio_interface.py CHANGED
@@ -12,32 +12,14 @@ def classify_text(text):
12
  predicted_labels = doc.cats
13
  return predicted_labels
14
 
15
- # Function to save results to a file
16
- def save_to_file(text, predicted_labels):
17
- with open("classification_results.txt", "w") as f:
18
- f.write("Text: {}\n\n".format(text))
19
- for label, score in predicted_labels.items():
20
- f.write("{}: {}\n".format(label, score))
21
-
22
  # Gradio Interface
23
- inputs = [
24
- gr.inputs.Textbox(lines=7, label="Enter your text"),
25
- gr.inputs.File(label="Upload a file")
26
- ]
27
-
28
- output = gr.outputs.Dataframe()
29
 
30
- def classify_and_save(input_text, input_file):
31
- if input_text:
32
- text = input_text
33
- elif input_file:
34
- # Process the file and extract text
35
- with open(input_file.name, "r") as f:
36
- text = f.read()
37
-
38
- predicted_labels = classify_text(text)
39
- save_to_file(text, predicted_labels)
40
  return predicted_labels
41
 
 
 
42
  iface = gr.Interface(fn=classify_and_save, inputs=inputs, outputs=output, title="Text Classifier")
43
  iface.launch(share=True)
 
12
  predicted_labels = doc.cats
13
  return predicted_labels
14
 
 
 
 
 
 
 
 
15
  # Gradio Interface
16
+ inputs = gr.inputs.Textbox(lines=7, label="Enter your text")
 
 
 
 
 
17
 
18
+ def classify_and_save(input_text):
19
+ predicted_labels = classify_text(input_text)
 
 
 
 
 
 
 
 
20
  return predicted_labels
21
 
22
+ output = gr.outputs.JSON(label="Classification Results")
23
+
24
  iface = gr.Interface(fn=classify_and_save, inputs=inputs, outputs=output, title="Text Classifier")
25
  iface.launch(share=True)