Update app.py
Browse files
app.py
CHANGED
@@ -34,12 +34,31 @@ def stream_chat_with_rag(
|
|
34 |
return answer, fig
|
35 |
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Create Gradio interface
|
39 |
with gr.Blocks(title="Reddit Election Analysis") as demo:
|
40 |
gr.Markdown("# Reddit Public sentiment & Social topic distribution ")
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
gr.Markdown("# Reddit Election Posts/Comments Analysis")
|
45 |
gr.Markdown("Ask questions about election-related comments and posts")
|
@@ -86,8 +105,18 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
|
|
86 |
width: 100%;
|
87 |
margin: auto;
|
88 |
}
|
|
|
|
|
|
|
|
|
|
|
89 |
</style>
|
90 |
""")
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
# Update both outputs when submit is clicked
|
93 |
submit_btn.click(
|
@@ -97,10 +126,5 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
|
|
97 |
)
|
98 |
|
99 |
|
100 |
-
|
101 |
if __name__ == "__main__":
|
102 |
-
demo.launch(share=True)
|
103 |
-
demo.launch(share_error=True)
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
34 |
return answer, fig
|
35 |
|
36 |
|
37 |
+
|
38 |
+
|
39 |
+
def heatmap(top_n):
|
40 |
+
fig = client.predict(
|
41 |
+
query= message,
|
42 |
+
election_year=client_name,
|
43 |
+
api_name="/heatmap"
|
44 |
+
)
|
45 |
+
return fig
|
46 |
|
47 |
# Create Gradio interface
|
48 |
with gr.Blocks(title="Reddit Election Analysis") as demo:
|
49 |
gr.Markdown("# Reddit Public sentiment & Social topic distribution ")
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column():
|
52 |
+
with gr.Row():
|
53 |
+
top_n = gr.Dropdown(choices= [1,2,3,4,5,6,7,8,9,10])
|
54 |
+
with gr.Row():
|
55 |
+
fresh_btn = gr.Button("Refresh Heatmap")
|
56 |
+
with gr.Column():
|
57 |
+
output_heatmap = gr.Plot(
|
58 |
+
label="Top Public sentiment & Social topic Heatmap",
|
59 |
+
container=True, # Ensures the plot is contained within its area
|
60 |
+
elem_classes="heatmap-plot" # Add a custom class for styling
|
61 |
+
)
|
62 |
|
63 |
gr.Markdown("# Reddit Election Posts/Comments Analysis")
|
64 |
gr.Markdown("Ask questions about election-related comments and posts")
|
|
|
105 |
width: 100%;
|
106 |
margin: auto;
|
107 |
}
|
108 |
+
.heatmap-plot {
|
109 |
+
min-height: 400px;
|
110 |
+
width: 100%;
|
111 |
+
margin: auto;
|
112 |
+
}
|
113 |
</style>
|
114 |
""")
|
115 |
+
fresh_btn.click(
|
116 |
+
fn=heatmap,
|
117 |
+
inputs=top_n,
|
118 |
+
outputs=output_heatmap
|
119 |
+
)
|
120 |
|
121 |
# Update both outputs when submit is clicked
|
122 |
submit_btn.click(
|
|
|
126 |
)
|
127 |
|
128 |
|
|
|
129 |
if __name__ == "__main__":
|
130 |
+
demo.launch(share=True)
|
|
|
|
|
|
|
|