rioanggara commited on
Commit
7c2306e
·
1 Parent(s): 2487585
Files changed (2) hide show
  1. app.py +45 -52
  2. requirements.txt +4 -1
app.py CHANGED
@@ -1,56 +1,49 @@
1
  import gradio as gr
2
- import requests
3
- import pandas as pd
4
  import matplotlib.pyplot as plt
5
- from datetime import datetime
6
-
7
- API_KEY = "PJRAUD6KHJ2O097X"
8
-
9
- def get_stock_data(symbol, start_date, end_date):
10
- url = f"https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol={symbol}&apikey={API_KEY}"
11
- response = requests.get(url)
12
- data = response.json()
13
-
14
- if "Time Series (Daily)" in data:
15
- df = pd.DataFrame(data["Time Series (Daily)"]).T
16
- df.index = pd.to_datetime(df.index)
17
-
18
- # Convert input dates to datetime
19
- try:
20
- start_datetime = datetime.strptime(start_date, '%Y-%m-%d')
21
- end_datetime = datetime.strptime(end_date, '%Y-%m-%d')
22
- df = df.loc[start_datetime:end_datetime]
23
- except ValueError:
24
- return "Invalid date format. Please use YYYY-MM-DD.", None
25
-
26
- df.columns = ["Open", "High", "Low", "Close", "Volume"]
27
-
28
- # Plotting
29
- plt.figure(figsize=(10, 5))
30
- plt.plot(df['Close'], label='Close Price')
31
- plt.title(f'Closing Price of {symbol}')
32
- plt.xlabel('Date')
33
- plt.ylabel('Price')
34
- plt.legend()
35
- plt.grid(True)
36
- plt.xticks(rotation=45)
37
- plt.tight_layout()
38
-
39
- return df.to_html(), gr.Image.from_matplotlib(plt)
40
- else:
41
- return "Data not found or invalid stock symbol.", None
42
-
43
- iface = gr.Interface(
44
- fn=get_stock_data,
45
- inputs=[
46
- gr.Textbox(label="Stock Symbol", placeholder="Enter a stock symbol (like AAPL, MSFT)"),
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
- if __name__ == "__main__":
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
- gradio
 
 
 
 
1
+ transformers==4.36.2
2
+ gradio==4.14.0
3
+ scikit-learn
4
+ matplotlib