Spaces:
Sleeping
Sleeping
ManjinderUNCC
commited on
Commit
•
b35bcf0
1
Parent(s):
56bcd0f
Delete gradio_interface.py
Browse files- gradio_interface.py +0 -43
gradio_interface.py
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
# Import necessary libraries
|
2 |
-
import gradio as gr
|
3 |
-
import spacy
|
4 |
-
|
5 |
-
# Load the trained spaCy model
|
6 |
-
model_path = "./my_trained_model"
|
7 |
-
nlp = spacy.load(model_path)
|
8 |
-
|
9 |
-
# Function to classify text
|
10 |
-
def classify_text(text):
|
11 |
-
doc = nlp(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.Textbox(label="Classification Results")
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|