nafisneehal commited on
Commit
2d1e9e0
·
verified ·
1 Parent(s): 0c7a866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +152 -4
app.py CHANGED
@@ -1,7 +1,155 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from fetch_plot_data import get_plot_data
5
 
 
 
6
 
7
+ def get_time_series_data():
8
+ # Fetch and process data
9
+ plot_data = get_plot_data(hours=24)
10
+ plot_data["datetime"] = pd.to_datetime(plot_data["datetime"])
11
+ time_series_data = pd.DataFrame({
12
+ "Datetime": plot_data["datetime"],
13
+ "Actual BTC/USD": plot_data["labels"],
14
+ "Predicted BTC/USD": plot_data["prediction"]
15
+ })
16
+ time_series_data = time_series_data.sort_values(by="Datetime")
17
+ time_series_data["Datetime"] = time_series_data["Datetime"].dt.strftime(
18
+ "%Y-%m-%d %H:%M")
19
+
20
+ all_values = np.concatenate([time_series_data["Actual BTC/USD"],
21
+ time_series_data["Predicted BTC/USD"]])
22
+ y_min = np.min(all_values)
23
+ y_max = np.max(all_values)
24
+ y_range = y_max - y_min
25
+ padding = y_range * 0.0005
26
+ y_min = y_min - padding
27
+ y_max = y_max + padding
28
+
29
+ long_data = time_series_data.melt(
30
+ id_vars="Datetime",
31
+ var_name="Series",
32
+ value_name="BTC/USD Value"
33
+ )
34
+ return (long_data, y_min, y_max)
35
+
36
+
37
+ custom_css = """
38
+ body {
39
+ background-color: #f8fafc !important;
40
+ }
41
+
42
+ .gradio-container {
43
+ max-width: 1200px !important;
44
+ margin: 2rem auto !important;
45
+ padding: 2rem !important;
46
+ background-color: white !important;
47
+ border-radius: 1rem !important;
48
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
49
+ }
50
+
51
+ .main-title {
52
+ color: #1e293b !important;
53
+ font-size: 2.5rem !important;
54
+ font-weight: 700 !important;
55
+ text-align: center !important;
56
+ margin-bottom: 0.5rem !important;
57
+ line-height: 1.2 !important;
58
+ }
59
+
60
+ .subtitle {
61
+ color: #64748b !important;
62
+ font-size: 1.125rem !important;
63
+ text-align: center !important;
64
+ margin-bottom: 1.5rem !important;
65
+ font-weight: 500 !important;
66
+ }
67
+
68
+ .chart-container {
69
+ margin-bottom: 1rem !important;
70
+ }
71
+
72
+ .footer-content {
73
+ margin-top: 1rem !important;
74
+ padding-top: 1rem !important;
75
+ border-top: 1px solid #e2e8f0 !important;
76
+ display: flex !important;
77
+ justify-content: space-between !important;
78
+ align-items: center !important;
79
+ color: #64748b !important;
80
+ font-size: 0.875rem !important;
81
+ }
82
+
83
+ .footer-left {
84
+ text-align: left !important;
85
+ }
86
+
87
+ .footer-right {
88
+ text-align: right !important;
89
+ }
90
+
91
+ .developer-info {
92
+ color: #3b82f6 !important;
93
+ font-weight: 500 !important;
94
+ text-decoration: none !important;
95
+ transition: color 0.2s !important;
96
+ }
97
+
98
+ .developer-info:hover {
99
+ color: #2563eb !important;
100
+ }
101
+ """
102
+
103
+ # Initialize the Gradio app
104
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as app:
105
+ with gr.Column():
106
+ # Title and subtitle
107
+ gr.Markdown("""
108
+ <div class="main-title">Live BTC/USD Time Series Info</div>
109
+ <div class="subtitle">Predictions served via Hopsworks API</div>
110
+ """)
111
+
112
+ initial_data, initial_y_min, initial_y_max = get_time_series_data()
113
+
114
+ # Chart with reduced bottom margin
115
+ with gr.Column(elem_classes=["chart-container"]):
116
+ line_plot = gr.LinePlot(
117
+ value=initial_data,
118
+ x="Datetime",
119
+ y="BTC/USD Value",
120
+ color="Series",
121
+ title="",
122
+ y_title="BTC/USD Value",
123
+ x_title="Time",
124
+ x_label_angle=45,
125
+ width=1000,
126
+ height=450, # Slightly reduced height
127
+ colors={
128
+ "Actual BTC/USD": "#3b82f6",
129
+ "Predicted BTC/USD": "#ef4444"
130
+ },
131
+ tooltip=["Datetime", "BTC/USD Value", "Series"],
132
+ overlay_point=True,
133
+ zoom=False,
134
+ pan=False,
135
+ show_label=True,
136
+ stroke_width=2,
137
+ y_min=initial_y_min,
138
+ y_max=initial_y_max,
139
+ y_lim=[initial_y_min, initial_y_max],
140
+ show_grid=True,
141
+ )
142
+
143
+ # Footer with timestamp and developer info
144
+ gr.Markdown(f"""
145
+ <div class="footer-content">
146
+ <div class="footer-left">
147
+ Last updated: {pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S")}
148
+ <br>
149
+ <a href="https://nafis-neehal.github.io/" target="_blank" class="developer-info">Developed by Nafis Neehal</a>
150
+ </div>
151
+ </div>
152
+ """)
153
+
154
+ # Launch the app
155
+ app.launch()