HonestAnnie commited on
Commit
92ed022
1 Parent(s): 2a5653d
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -56,13 +56,19 @@ def update_authors(database):
56
 
57
 
58
 
59
- with gr.Blocks() as demo:
60
  gr.Markdown("Enter your query, filter authors (default is all), click **Search** to search.")
61
  database_inp = gr.Dropdown(label="Database", choices=["English", "German"], value="German")
62
  author_inp = gr.Dropdown(label="Authors", choices=authors_list_de, multiselect=True)
63
  inp = gr.Textbox(label="Query", placeholder="Enter questions separated by semicolons...")
64
  btn = gr.Button("Search")
65
- results = gr.State() # Store results in a State component
 
 
 
 
 
 
66
 
67
  def perform_query(queries, authors, database):
68
  task = "Given a question, retrieve passages that answer the question"
@@ -83,22 +89,10 @@ with gr.Blocks() as demo:
83
 
84
  @gr.render(inputs=[results])
85
  def display_accordion(data):
86
- output_blocks = []
87
  for query, res in data:
88
- with gr.Accordion(query) as acc:
89
- if not res:
90
- markdown_contents = "No results found."
91
- elif "error" in res[0]:
92
- markdown_contents = f"Error retrieving data: {res[0]['error']}"
93
- else:
94
- markdown_contents = "\n".join(f"**{r['author']}, {r['book']}**\n\n{r['text']}" for r in res)
95
- gr.Markdown(markdown_contents)
96
-
97
-
98
- database_inp.change(
99
- fn=lambda database: update_authors(database),
100
- inputs=[database_inp],
101
- outputs=[author_inp]
102
- )
103
 
104
  demo.launch()
 
56
 
57
 
58
 
59
+ with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; border-radius: 5px; }") as demo:
60
  gr.Markdown("Enter your query, filter authors (default is all), click **Search** to search.")
61
  database_inp = gr.Dropdown(label="Database", choices=["English", "German"], value="German")
62
  author_inp = gr.Dropdown(label="Authors", choices=authors_list_de, multiselect=True)
63
  inp = gr.Textbox(label="Query", placeholder="Enter questions separated by semicolons...")
64
  btn = gr.Button("Search")
65
+ results = gr.State()
66
+
67
+ database_inp.change(
68
+ fn=lambda database: update_authors(database),
69
+ inputs=[database_inp],
70
+ outputs=[author_inp]
71
+ )
72
 
73
  def perform_query(queries, authors, database):
74
  task = "Given a question, retrieve passages that answer the question"
 
89
 
90
  @gr.render(inputs=[results])
91
  def display_accordion(data):
 
92
  for query, res in data:
93
+ with gr.Accordion(query, open=False) as acc:
94
+ markdown_contents = "\n".join(f"**{r['author']}, {r['book']}**\n\n{r['text']}" for r in res)
95
+ with gr.Column():
96
+ gr.Markdown(value=markdown_contents, elem_classes="custom-markdown")
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  demo.launch()