Spaces:
Runtime error
Runtime error
File size: 3,538 Bytes
f3d0f1e 33014c1 f3d0f1e 33014c1 f3d0f1e 33014c1 0d7e513 33014c1 0d7e513 33014c1 f3d0f1e 85e76f5 f3d0f1e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import gradio as gr
from src.chatbot import chatbot, keyword_search
with gr.Blocks() as App:
with gr.Tab("ChatBot"):
#Apply RAG using chatbut function from local file ChatBot.py
gr.ChatInterface(chatbot,
title="PoliticsToYou",
description= "This chatbot uses the infomation of speeches of the german parliament (since 2021) \
to get insight on the view points of the german parties and the debate of the parliament.",
examples=["Wie steht die CDU zur Cannabislegalisierung?","Was waren die wichtigsten Themen in der aktuellen Legislaturperiode?"], #change to meaningful examples
cache_examples=False, #true increases the loading time
)
with gr.Tab("KeyWordSearch"):
with gr.Blocks() as Block:
#Keyword Input
keyword_box = gr.Textbox(label='keyword')
#Additional Input (hidden)
with gr.Accordion('Detailed filters', open=False):
#Row orientation
with gr.Row() as additional_input:
n_slider = gr.Slider(label="Number of Results", minimum=1, maximum=100, step=1, value=10)
party_dopdown = gr.Dropdown(choices=['CDU/CSU','SPD','FDP','Grüne','not found','DIE LINKE.','PDS','KPD'], label='Party')
search_btn = gr.Button('Search')
with gr.Column(visible=False) as output_col:
results_df = gr.Dataframe(label='Results', interactive=False)
#Download results from keyword search
with gr.Accordion('Would you like to download your results?', open=False) as download_row:
with gr.Row():
ftype_dropdown = gr.Dropdown(choices=["csv","excel","json"], label="Format")
export_btn = gr.Button('Export')
file = gr.File(file_types=[".xlsx", ".csv", ".json"], visible=False)
#Keyword Search on click
def search(keyword, n, party): #ToDo: Include party and timedate
return {
output_col: gr.Column(visible=True),
results_df: keyword_search(query=keyword, n=n, party_filter=party),
}
search_btn.click(
fn=search,
inputs=[keyword_box, n_slider, party_dopdown],
outputs=[output_col, results_df],
)
#Export data to a downloadable format
def export(df, keyword, ftype=None):
if ftype == "csv":
file = f'{keyword}.csv'
df.to_csv(file, index = False)
return gr.File(value=file,visible=True)
elif ftype == "json":
file = f'{keyword}.json'
df.to_json(file, index = True)
return gr.File(value=file,visible=True)
else:
file = f'{keyword}.xlsx'
df.to_excel(file, index = True)
return gr.File(value=file,visible=True)
export_btn.click(
fn=export,
inputs=[results_df, keyword_box, ftype_dropdown],
outputs=[file],
)
if __name__ == "__main__":
App.launch(share=False) #true not supported on hf spaces
|