Spaces:
Sleeping
Sleeping
Commit
·
38cc304
1
Parent(s):
8c6f469
load the app with model
Browse files
app.py
CHANGED
|
@@ -1,43 +1,57 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
+
|
| 4 |
+
#load the model directly
|
| 5 |
+
# Use a pipeline as a high-level helper
|
| 6 |
+
pipe = pipeline("text-classification", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
#run the application
|
| 10 |
+
demo=gr.Interface.from_pipeline(pipe)
|
| 11 |
+
demo.launch()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# import gradio as gr
|
| 16 |
+
# from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 17 |
+
# import torch
|
| 18 |
+
|
| 19 |
+
# # Load the pre-trained model and tokenizer
|
| 20 |
+
# tokenizer = AutoTokenizer.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
|
| 21 |
+
# model = AutoModelForSequenceClassification.from_pretrained("mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
|
| 22 |
+
|
| 23 |
+
# # Define a function for sentiment analysis
|
| 24 |
+
# def predict_sentiment(text):
|
| 25 |
+
# # Tokenize the input text and prepare it to be used by the model
|
| 26 |
+
# inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 27 |
+
|
| 28 |
+
# # Forward pass through the model
|
| 29 |
+
# with torch.no_grad():
|
| 30 |
+
# outputs = model(**inputs)
|
| 31 |
+
|
| 32 |
+
# # Get the predicted probabilities and convert them to percentages
|
| 33 |
+
# probabilities = torch.softmax(outputs.logits, dim=1).squeeze().tolist()
|
| 34 |
+
# positive_percent = probabilities[2] * 100
|
| 35 |
+
# negative_percent = probabilities[0] * 100
|
| 36 |
+
# neutral_percent = probabilities[1] * 100
|
| 37 |
+
|
| 38 |
+
# # Construct the result dictionary
|
| 39 |
+
# result = {
|
| 40 |
+
# "Positive": round(positive_percent, 2),
|
| 41 |
+
# "Negative": round(negative_percent, 2),
|
| 42 |
+
# "Neutral": round(neutral_percent, 2)
|
| 43 |
+
# }
|
| 44 |
+
|
| 45 |
+
# return result
|
| 46 |
+
|
| 47 |
+
# # Define inputs and outputs directly without using gr.inputs or gr.outputs
|
| 48 |
+
# iface = gr.Interface(
|
| 49 |
+
# fn=predict_sentiment,
|
| 50 |
+
# inputs=gr.inputs.Textbox(lines=10, label="Enter financial statement"),
|
| 51 |
+
# outputs=gr.outputs.Label(num_top_classes=3, label="Sentiment Percentages"),
|
| 52 |
+
# title="Financial Statement Sentiment Analysis",
|
| 53 |
+
# description="Predict the sentiment percentages of a financial statement."
|
| 54 |
+
# )
|
| 55 |
+
|
| 56 |
+
# if __name__ == "__main__":
|
| 57 |
+
# iface.launch()
|