dlnlm commited on
Commit
fa9c7ad
·
verified ·
1 Parent(s): 2eeee7d

Upload 3 files

Browse files
Files changed (3) hide show
  1. DBS_SingDollar.csv +123 -0
  2. app.py +71 -0
  3. requirements.txt +3 -0
DBS_SingDollar.csv ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ,Date,DBS,SGD
2
+ 1,6/20/2017,20.45,1.38925
3
+ 2,6/19/2017,20.6,1.38707
4
+ 3,6/16/2017,20.45,1.38324
5
+ 4,6/15/2017,20.41,1.38378
6
+ 5,6/14/2017,20.59,1.37595
7
+ 6,6/13/2017,20.78,1.38172
8
+ 7,6/12/2017,20.59,1.38424
9
+ 8,6/9/2017,20.72,1.38401
10
+ 9,6/8/2017,20.47,1.3827
11
+ 10,6/7/2017,20.43,1.38187
12
+ 11,6/6/2017,20.49,1.37925
13
+ 12,6/5/2017,20.49,1.38157
14
+ 13,6/2/2017,20.48,1.38104
15
+ 14,6/1/2017,20.65,1.38653
16
+ 15,5/31/2017,20.47,1.3832
17
+ 16,5/30/2017,20.6,1.3853
18
+ 17,5/29/2017,20.84,1.38665
19
+ 18,5/26/2017,20.8,1.38071
20
+ 19,5/25/2017,21.04,1.38634
21
+ 20,5/24/2017,21,1.38451
22
+ 21,5/23/2017,21,1.38995
23
+ 22,5/22/2017,20.86,1.38642
24
+ 23,5/19/2017,20.7,1.38523
25
+ 24,5/18/2017,20.63,1.39297
26
+ 25,5/17/2017,20.8,1.38981
27
+ 26,5/16/2017,20.65,1.39474
28
+ 27,5/15/2017,20.77,1.39749
29
+ 28,5/12/2017,20.68,1.40394
30
+ 29,5/11/2017,20.93,1.40746
31
+ 30,5/9/2017,20.5,1.41128
32
+ 31,5/8/2017,20.3,1.40604
33
+ 32,5/5/2017,20.42,1.40496
34
+ 33,5/4/2017,20.45,1.40069
35
+ 34,5/3/2017,20.53,1.39724
36
+ 35,5/2/2017,19.57,1.39379
37
+ 36,4/28/2017,19.07,1.39739
38
+ 37,4/27/2017,18.93,1.3971
39
+ 38,4/26/2017,19.03,1.39598
40
+ 39,4/25/2017,18.92,1.39412
41
+ 40,4/24/2017,18.73,1.39261
42
+ 41,4/21/2017,18.5,1.39655
43
+ 42,4/20/2017,18.64,1.39772
44
+ 43,4/19/2017,18.52,1.39821
45
+ 44,4/18/2017,18.65,1.39584
46
+ 45,4/17/2017,18.63,1.39794
47
+ 46,4/13/2017,18.82,1.39799
48
+ 47,4/12/2017,18.97,1.39653
49
+ 48,4/11/2017,18.88,1.40404
50
+ 49,4/10/2017,18.85,1.4048
51
+ 50,4/7/2017,18.78,1.40474
52
+ 51,4/6/2017,18.85,1.40211
53
+ 52,4/5/2017,18.93,1.40067
54
+ 53,4/4/2017,18.95,1.39817
55
+ 54,4/3/2017,19.12,1.3971
56
+ 55,3/31/2017,19.12,1.39639
57
+ 56,3/30/2017,19.02,1.39769
58
+ 57,3/29/2017,19.01,1.39407
59
+ 58,3/28/2017,18.75,1.39677
60
+ 59,3/27/2017,18.43,1.39397
61
+ 60,3/24/2017,18.52,1.39885
62
+ 61,3/23/2017,18.38,1.3997
63
+ 62,3/22/2017,18.4,1.39854
64
+ 63,3/21/2017,18.73,1.39934
65
+ 64,3/20/2017,18.74,1.39688
66
+ 65,3/17/2017,18.86,1.40201
67
+ 66,3/16/2017,18.84,1.40121
68
+ 67,3/15/2017,18.85,1.40224
69
+ 68,3/14/2017,18.91,1.41592
70
+ 69,3/13/2017,18.83,1.41477
71
+ 70,3/10/2017,18.66,1.41173
72
+ 71,3/9/2017,18.67,1.42132
73
+ 72,3/8/2017,19,1.41763
74
+ 73,3/7/2017,18.82,1.41135
75
+ 74,3/6/2017,18.79,1.41235
76
+ 75,3/3/2017,18.74,1.41037
77
+ 76,3/2/2017,18.76,1.41213
78
+ 77,3/1/2017,18.55,1.40907
79
+ 78,2/28/2017,18.46,1.405
80
+ 79,2/27/2017,18.54,1.40429
81
+ 80,2/24/2017,18.6,1.40447
82
+ 81,2/23/2017,18.62,1.40763
83
+ 82,2/22/2017,18.48,1.41323
84
+ 83,2/21/2017,18.19,1.42045
85
+ 84,2/20/2017,18.23,1.41793
86
+ 85,2/17/2017,18.33,1.41901
87
+ 86,2/16/2017,18.27,1.41659
88
+ 87,2/15/2017,17.97,1.41906
89
+ 88,2/14/2017,18,1.41995
90
+ 89,2/13/2017,18.64,1.42416
91
+ 90,2/10/2017,18.7,1.42058
92
+ 91,2/9/2017,18.55,1.42066
93
+ 92,2/8/2017,18.53,1.41667
94
+ 93,2/7/2017,18.59,1.41857
95
+ 94,2/6/2017,18.66,1.40917
96
+ 95,2/3/2017,18.39,1.40746
97
+ 96,2/2/2017,18.51,1.41138
98
+ 97,2/1/2017,18.61,1.41244
99
+ 98,1/31/2017,18.7,1.40954
100
+ 99,1/27/2017,18.89,1.43178
101
+ 100,1/26/2017,18.76,1.42589
102
+ 101,1/25/2017,18.58,1.41285
103
+ 102,1/24/2017,18.39,1.42117
104
+ 103,1/23/2017,18.08,1.41598
105
+ 104,1/20/2017,18.01,1.42705
106
+ 105,1/19/2017,18.02,1.42616
107
+ 106,1/18/2017,17.94,1.42876
108
+ 107,1/17/2017,18.09,1.41601
109
+ 108,1/16/2017,18.06,1.4303
110
+ 109,1/13/2017,18.05,1.42592
111
+ 110,1/12/2017,17.86,1.42728
112
+ 111,1/11/2017,17.78,1.42678
113
+ 112,1/10/2017,17.73,1.43654
114
+ 113,1/9/2017,17.59,1.43529
115
+ 114,1/6/2017,17.42,1.43938
116
+ 115,1/5/2017,17.54,1.42847
117
+ 116,1/4/2017,17.27,1.43942
118
+ 117,1/3/2017,17.07,1.44992
119
+ 118,12/30/2016,17.09,1.44655
120
+ 119,12/29/2016,17.13,1.44814
121
+ 120,12/28/2016,17.22,1.45018
122
+ 121,12/27/2016,17.19,1.44954
123
+ 122,12/23/2016,17.14,1.44766
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pandas as pd
3
+ import gradio as gr
4
+ from groq import Groq
5
+ from sklearn.model_selection import train_test_split
6
+ from sklearn.linear_model import LinearRegression
7
+
8
+ # =========================================================
9
+ # 1️⃣ GROQ CHATBOT (App 1)
10
+ # =========================================================
11
+
12
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
13
+
14
+ def groq_chat(text):
15
+ """Chat interface powered by Groq LLM."""
16
+ completion = client.chat.completions.create(
17
+ model="llama-3.1-8b-instant",
18
+ messages=[{"role": "user", "content": text}]
19
+ )
20
+ return completion.choices[0].message.content
21
+
22
+
23
+ # =========================================================
24
+ # 2️⃣ DBS Regression Model (App 2)
25
+ # =========================================================
26
+
27
+ # Load local CSV (must be uploaded into the HF Space)
28
+ df = pd.read_csv("DBS_SingDollar.csv")
29
+ df = df[["DBS", "SGD"]].dropna()
30
+
31
+ # Prepare data
32
+ X = df[["SGD"]]
33
+ y = df["DBS"]
34
+
35
+ X_train, X_test, y_train, y_test = train_test_split(
36
+ X, y, test_size=0.2, random_state=42
37
+ )
38
+
39
+ model = LinearRegression()
40
+ model.fit(X_train, y_train)
41
+
42
+ def predict_dbs_price(sgd_rate: float):
43
+ """Predict DBS share price from SGD exchange rate."""
44
+ pred = model.predict([[sgd_rate]])[0]
45
+ return f"Predicted DBS Share Price: {pred:.2f}"
46
+
47
+
48
+ # =========================================================
49
+ # 3️⃣ BUILD MULTI-APP GRADIO UI
50
+ # =========================================================
51
+
52
+ with gr.Blocks() as app:
53
+ gr.Markdown("## 🚀 Multi-App: Groq Chatbot + DBS Share Price Predictor (CPU Version)")
54
+
55
+ # ---- TAB 1: Groq Chatbot ----
56
+ with gr.Tab("💬 Groq Chatbot"):
57
+ user_in = gr.Textbox(label="Enter your message:", lines=4)
58
+ bot_out = gr.Textbox(label="Model Reply:", lines=8)
59
+ send_btn = gr.Button("Send")
60
+ send_btn.click(fn=groq_chat, inputs=user_in, outputs=bot_out)
61
+
62
+ # ---- TAB 2: DBS Predictor ----
63
+ with gr.Tab("📈 DBS Price Predictor"):
64
+ rate_in = gr.Number(label="SGD Exchange Rate")
65
+ result_out = gr.Textbox(label="Predicted DBS Price")
66
+ predict_btn = gr.Button("Predict")
67
+ predict_btn.click(fn=predict_dbs_price, inputs=rate_in, outputs=result_out)
68
+
69
+ if __name__ == "__main__":
70
+ app.launch()
71
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ groq
2
+ gradio
3
+ scikit-learn