Spaces:
Sleeping
Sleeping
Commit
·
7c2306e
1
Parent(s):
2487585
wew
Browse files- app.py +45 -52
- requirements.txt +4 -1
app.py
CHANGED
@@ -1,56 +1,49 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
import matplotlib.pyplot as plt
|
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 |
-
|
44 |
-
fn=
|
45 |
-
inputs=
|
46 |
-
|
47 |
-
gr.Textbox(label="Start Date", placeholder="YYYY-MM-DD"),
|
48 |
-
gr.Textbox(label="End Date", placeholder="YYYY-MM-DD")
|
49 |
-
],
|
50 |
-
outputs=["html", "plot"],
|
51 |
-
title="Personalized Stock Market Data App",
|
52 |
-
description="Enter a stock symbol and date range to fetch its daily time series data."
|
53 |
)
|
54 |
|
55 |
-
|
56 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix, roc_curve, auc
|
4 |
import matplotlib.pyplot as plt
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
# Initialize the sentiment analysis pipeline with a multilingual model
|
8 |
+
sentiment_analysis = pipeline("sentiment-analysis", model="bert-base-multilingual-cased")
|
9 |
+
|
10 |
+
def analyze_sentiment(text):
|
11 |
+
result = sentiment_analysis(text)
|
12 |
+
return result[0]
|
13 |
+
|
14 |
+
# Mock functions to calculate metrics - Replace with actual implementation
|
15 |
+
def calculate_metrics(y_true, y_pred):
|
16 |
+
accuracy = accuracy_score(y_true, y_pred)
|
17 |
+
precision, recall, f1, _ = precision_recall_fscore_support(y_true, y_pred, average='binary')
|
18 |
+
cm = confusion_matrix(y_true, y_pred)
|
19 |
+
fpr, tpr, _ = roc_curve(y_true, y_pred)
|
20 |
+
roc_auc = auc(fpr, tpr)
|
21 |
+
return accuracy, precision, recall, f1, cm, fpr, tpr, roc_auc
|
22 |
+
|
23 |
+
def plot_confusion_matrix(cm):
|
24 |
+
# Plot confusion matrix here
|
25 |
+
pass
|
26 |
+
|
27 |
+
def plot_roc_curve(fpr, tpr, roc_auc):
|
28 |
+
# Plot ROC curve here
|
29 |
+
pass
|
30 |
+
|
31 |
+
# Replace this with actual test data and predictions
|
32 |
+
y_true = [0, 1, 0, 1] # True labels
|
33 |
+
y_pred = [0, 1, 0, 1] # Predicted labels
|
34 |
+
|
35 |
+
# Calculate metrics
|
36 |
+
accuracy, precision, recall, f1, cm, fpr, tpr, roc_auc = calculate_metrics(y_true, y_pred)
|
37 |
+
|
38 |
+
# Plot confusion matrix and ROC curve
|
39 |
+
plot_confusion_matrix(cm)
|
40 |
+
plot_roc_curve(fpr, tpr, roc_auc)
|
41 |
+
|
42 |
+
# Create a Gradio interface
|
43 |
+
interface = gr.Interface(
|
44 |
+
fn=analyze_sentiment,
|
45 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Text Here..."),
|
46 |
+
outputs="text"
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
)
|
48 |
|
49 |
+
interface.launch()
|
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
1 |
+
transformers==4.36.2
|
2 |
+
gradio==4.14.0
|
3 |
+
scikit-learn
|
4 |
+
matplotlib
|