Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -47,35 +47,55 @@ def stream_chat_with_rag(
|
|
47 |
|
48 |
return answer
|
49 |
|
50 |
-
CSS = """
|
51 |
-
# chat-container {
|
52 |
-
height: 100vh;
|
53 |
-
}
|
54 |
-
"""
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
# Title for the application
|
59 |
-
TITLE = "<h1 style='text-align:center;'>Reddit Election Q&A agent v0.2</h1>"
|
60 |
-
|
61 |
-
# Create the Gradio Blocks interface
|
62 |
-
with gr.Blocks(css=CSS) as demo:
|
63 |
-
gr.HTML(TITLE)
|
64 |
-
with gr.Tab("Chat"):
|
65 |
-
chatbot = gr.Chatbot() # Create a chatbot interface
|
66 |
-
chat_interface = gr.ChatInterface(
|
67 |
-
fn=stream_chat_with_rag,
|
68 |
-
chatbot=chatbot,
|
69 |
-
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
70 |
-
additional_inputs=[
|
71 |
-
gr.Dropdown(client_name,value="2016 Election",label="Select Election year", render=False,allow_custom_value=True)
|
72 |
-
],
|
73 |
-
)
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
-
# Launch the app
|
77 |
if __name__ == "__main__":
|
78 |
-
demo.launch()
|
79 |
|
80 |
|
81 |
|
|
|
47 |
|
48 |
return answer
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
# Create Gradio interface
|
53 |
+
with gr.Blocks(title="Reddit Election Comments Analysis") as demo:
|
54 |
+
gr.Markdown("# Reddit Election Comments Analysis")
|
55 |
+
gr.Markdown("Ask questions about election-related comments and posts")
|
56 |
+
|
57 |
+
with gr.Row():
|
58 |
+
with gr.Column():
|
59 |
+
# Add election year selector
|
60 |
+
year_selector = gr.Radio(
|
61 |
+
choices=["2016 Election", "2024 Election", "Comparison two years"],
|
62 |
+
label="Select Election Year",
|
63 |
+
value="2016 Election" # Default value
|
64 |
+
)
|
65 |
+
|
66 |
+
query_input = gr.Textbox(
|
67 |
+
label="Your Question",
|
68 |
+
placeholder="Ask about election comments or posts..."
|
69 |
+
)
|
70 |
+
# context_input = gr.Textbox(
|
71 |
+
# label="Context (Optional)",
|
72 |
+
# value = "Looking for discussions about the election results in 2016" #default value
|
73 |
+
# )
|
74 |
+
submit_btn = gr.Button("Submit")
|
75 |
+
|
76 |
+
with gr.Column():
|
77 |
+
output = gr.Textbox(
|
78 |
+
label="Response",
|
79 |
+
lines=20
|
80 |
+
)
|
81 |
+
|
82 |
+
# Update submit button to include year selection
|
83 |
+
submit_btn.click(
|
84 |
+
fn=stream_chat_with_rag,
|
85 |
+
inputs=[query_input, year_selector],
|
86 |
+
outputs=output
|
87 |
+
)
|
88 |
+
|
89 |
+
gr.Markdown("""
|
90 |
+
## Example Questions:
|
91 |
+
- Is there any comments don't like the election results
|
92 |
+
- Summarize the main discussions about voting process
|
93 |
+
- What are the common opinions about candidates?
|
94 |
+
- How have people's attitudes toward the Republican Party changed in the past two years?
|
95 |
+
""")
|
96 |
|
|
|
97 |
if __name__ == "__main__":
|
98 |
+
demo.launch(share=True)
|
99 |
|
100 |
|
101 |
|