Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,6 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassifica
|
|
| 6 |
model_NER = AutoModelForTokenClassification.from_pretrained("./NER_model")
|
| 7 |
tokenizer_NER = AutoTokenizer.from_pretrained("./tokenizer_NER")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
model_path = './model'
|
| 12 |
tokenizer_path = './tokenizer'
|
| 13 |
|
|
@@ -20,25 +18,14 @@ clf_ner = pipeline("ner", model=model_NER, tokenizer=tokenizer_NER)
|
|
| 20 |
config = AutoConfig.from_pretrained("./NER_model")
|
| 21 |
label_list = config.id2label
|
| 22 |
|
| 23 |
-
def tokenize_NER(input_text):
|
| 24 |
-
tokenized_text = tokenizer_NER(input_text, padding='max_length', truncation=True, max_length=512)
|
| 25 |
-
return tokenized_text
|
| 26 |
-
|
| 27 |
-
def tokenize_sentiment(input_text):
|
| 28 |
-
tokenized_text = tokenizer_sentiment(input_text, padding='max_length', truncation=True, max_length=512)
|
| 29 |
-
return tokenized_text
|
| 30 |
-
|
| 31 |
def analyze_sentiment(text):
|
| 32 |
-
text = tokenizer_sentiment(text)
|
| 33 |
predictions = clf_sentiment(text)
|
| 34 |
label_mapping = {'LABEL_0': 'Negative', 'LABEL_1': 'Neutral', 'LABEL_2': 'Positive'}
|
| 35 |
predicted_label = label_mapping[predictions[0]['label']]
|
| 36 |
confidence = f"{predictions[0]['score'] * 100:.2f}%"
|
| 37 |
return f"Predicted Label: {predicted_label}\nConfidence: {confidence}"
|
| 38 |
|
| 39 |
-
|
| 40 |
def analyze_ner(text):
|
| 41 |
-
text = tokenize_NER(text)
|
| 42 |
predictions = clf_ner(text)
|
| 43 |
print(predictions) # Debugging statement to see the structure of the output
|
| 44 |
|
|
@@ -83,4 +70,4 @@ interface = gr.Interface(
|
|
| 83 |
)
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
-
interface.launch()
|
|
|
|
| 6 |
model_NER = AutoModelForTokenClassification.from_pretrained("./NER_model")
|
| 7 |
tokenizer_NER = AutoTokenizer.from_pretrained("./tokenizer_NER")
|
| 8 |
|
|
|
|
|
|
|
| 9 |
model_path = './model'
|
| 10 |
tokenizer_path = './tokenizer'
|
| 11 |
|
|
|
|
| 18 |
config = AutoConfig.from_pretrained("./NER_model")
|
| 19 |
label_list = config.id2label
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def analyze_sentiment(text):
|
|
|
|
| 22 |
predictions = clf_sentiment(text)
|
| 23 |
label_mapping = {'LABEL_0': 'Negative', 'LABEL_1': 'Neutral', 'LABEL_2': 'Positive'}
|
| 24 |
predicted_label = label_mapping[predictions[0]['label']]
|
| 25 |
confidence = f"{predictions[0]['score'] * 100:.2f}%"
|
| 26 |
return f"Predicted Label: {predicted_label}\nConfidence: {confidence}"
|
| 27 |
|
|
|
|
| 28 |
def analyze_ner(text):
|
|
|
|
| 29 |
predictions = clf_ner(text)
|
| 30 |
print(predictions) # Debugging statement to see the structure of the output
|
| 31 |
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
| 73 |
+
interface.launch(share=True)
|