Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,12 +9,13 @@ HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using
|
|
9 |
# Initialize the Gradio Client for the specified API
|
10 |
client = Client("mangoesai/Elections_Comparison_Agent_V4", hf_token=HF_TOKEN)
|
11 |
|
12 |
-
|
13 |
|
14 |
|
15 |
|
16 |
def stream_chat_with_rag(
|
17 |
message: str,
|
|
|
18 |
client_name: str
|
19 |
):
|
20 |
# print(f"Message: {message}")
|
@@ -32,36 +33,11 @@ def stream_chat_with_rag(
|
|
32 |
|
33 |
return answer, fig
|
34 |
|
35 |
-
def heatmap(top_n):
|
36 |
-
map = client.predict(
|
37 |
-
top_n = top_n,
|
38 |
-
api_name = "/heatmap"
|
39 |
-
)
|
40 |
-
|
41 |
-
return map
|
42 |
-
|
43 |
|
44 |
|
45 |
# Create Gradio interface
|
46 |
with gr.Blocks(title="Reddit Election Analysis") as demo:
|
47 |
-
gr.Markdown("# Reddit Public sentiment & Social topic
|
48 |
-
with gr.Row():
|
49 |
-
with gr.Column():
|
50 |
-
with gr.Row():
|
51 |
-
top_n = gr.Dropdown(choices= [1,2,3,4,5,6,7,8,9,10])
|
52 |
-
with gr.Row():
|
53 |
-
fresh_btn = gr.Button("Refresh Heatmap")
|
54 |
-
with gr.Column():
|
55 |
-
output_heatmap = gr.Plot(
|
56 |
-
label="Top Public sentiment & Social topic Heatmap",
|
57 |
-
container=True, # Ensures the plot is contained within its area
|
58 |
-
elem_classes="heatmap-plot" # Add a custom class for styling
|
59 |
-
)
|
60 |
-
fresh_btn.click(
|
61 |
-
fn=heatmap,
|
62 |
-
inputs=top_n,
|
63 |
-
outputs=output_heatmap
|
64 |
-
)
|
65 |
|
66 |
|
67 |
|
@@ -78,8 +54,7 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
|
|
78 |
|
79 |
query_input = gr.Textbox(
|
80 |
label="Your Question",
|
81 |
-
placeholder="Ask about election comments or posts
|
82 |
-
value = "Is there any comments don't like the election results"
|
83 |
)
|
84 |
|
85 |
submit_btn = gr.Button("Submit")
|
@@ -111,11 +86,6 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
|
|
111 |
width: 100%;
|
112 |
margin: auto;
|
113 |
}
|
114 |
-
.heatmap-plot {
|
115 |
-
min-height: 400px;
|
116 |
-
width: 100%;
|
117 |
-
margin: auto;
|
118 |
-
}
|
119 |
</style>
|
120 |
""")
|
121 |
|
@@ -127,8 +97,9 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
|
|
127 |
)
|
128 |
|
129 |
|
|
|
130 |
if __name__ == "__main__":
|
131 |
-
demo.launch(share=True
|
132 |
|
133 |
|
134 |
|
|
|
9 |
# Initialize the Gradio Client for the specified API
|
10 |
client = Client("mangoesai/Elections_Comparison_Agent_V4", hf_token=HF_TOKEN)
|
11 |
|
12 |
+
client_name = ['2016 Election','2024 Election', 'Comparison two years']
|
13 |
|
14 |
|
15 |
|
16 |
def stream_chat_with_rag(
|
17 |
message: str,
|
18 |
+
# history: list,
|
19 |
client_name: str
|
20 |
):
|
21 |
# print(f"Message: {message}")
|
|
|
33 |
|
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 |
|
|
|
54 |
|
55 |
query_input = gr.Textbox(
|
56 |
label="Your Question",
|
57 |
+
placeholder="Ask about election comments or posts..."
|
|
|
58 |
)
|
59 |
|
60 |
submit_btn = gr.Button("Submit")
|
|
|
86 |
width: 100%;
|
87 |
margin: auto;
|
88 |
}
|
|
|
|
|
|
|
|
|
|
|
89 |
</style>
|
90 |
""")
|
91 |
|
|
|
97 |
)
|
98 |
|
99 |
|
100 |
+
|
101 |
if __name__ == "__main__":
|
102 |
+
demo.launch(share=True)
|
103 |
|
104 |
|
105 |
|