Spaces:
Sleeping
Sleeping
Update gradio_interface.py
Browse files- gradio_interface.py +2 -18
gradio_interface.py
CHANGED
@@ -5,18 +5,6 @@ import spacy
|
|
5 |
model_path = "./my_trained_model"
|
6 |
nlp = spacy.load(model_path)
|
7 |
|
8 |
-
# Threshold for classification
|
9 |
-
threshold = 0.21
|
10 |
-
|
11 |
-
# Ground truth labels
|
12 |
-
ground_truth_labels = {
|
13 |
-
"CapitalRequirements": 0,
|
14 |
-
"ConsumerProtection": 1,
|
15 |
-
"RiskManagement": 0,
|
16 |
-
"ReportingAndCompliance": 1,
|
17 |
-
"CorporateGovernance": 0
|
18 |
-
}
|
19 |
-
|
20 |
# Function to classify text
|
21 |
def classify_text(text):
|
22 |
doc = nlp(text)
|
@@ -31,20 +19,16 @@ def evaluate_text(input_text):
|
|
31 |
|
32 |
# Construct output dictionary with likelihood for each label
|
33 |
output_dict = {
|
34 |
-
"PredictedLabels": {label: score for label, score in predicted_labels.items()
|
35 |
}
|
36 |
|
37 |
-
# Add likelihood for each ground truth label
|
38 |
-
for label in ground_truth_labels:
|
39 |
-
if label not in output_dict["PredictedLabels"]:
|
40 |
-
output_dict["PredictedLabels"][label] = 0 # Set likelihood to 0 if label not present
|
41 |
-
|
42 |
return output_dict
|
43 |
|
44 |
# Gradio Interface
|
45 |
iface = gr.Interface(fn=evaluate_text, inputs="text", outputs="json", title="Text Evaluation-Manjinder", description="Enter your text")
|
46 |
iface.launch(share=True)
|
47 |
|
|
|
48 |
# import gradio as gr
|
49 |
# import spacy
|
50 |
# from sklearn.metrics import classification_report, accuracy_score, f1_score, precision_score, recall_score
|
|
|
5 |
model_path = "./my_trained_model"
|
6 |
nlp = spacy.load(model_path)
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Function to classify text
|
9 |
def classify_text(text):
|
10 |
doc = nlp(text)
|
|
|
19 |
|
20 |
# Construct output dictionary with likelihood for each label
|
21 |
output_dict = {
|
22 |
+
"PredictedLabels": {label: score for label, score in predicted_labels.items()}
|
23 |
}
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
return output_dict
|
26 |
|
27 |
# Gradio Interface
|
28 |
iface = gr.Interface(fn=evaluate_text, inputs="text", outputs="json", title="Text Evaluation-Manjinder", description="Enter your text")
|
29 |
iface.launch(share=True)
|
30 |
|
31 |
+
|
32 |
# import gradio as gr
|
33 |
# import spacy
|
34 |
# from sklearn.metrics import classification_report, accuracy_score, f1_score, precision_score, recall_score
|