gfacini commited on
Commit
0004b8d
·
verified ·
1 Parent(s): c65511c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -35
app.py CHANGED
@@ -2,51 +2,40 @@ import gradio as gr
2
  from datetime import datetime
3
 
4
  def search(query, collections):
5
- # Placeholder function where you'd integrate your custom RAG logic
6
- # For now, it just echoes the input back with a mock response
7
  response = f"Results for query: {query} from collections: {', '.join(collections)}"
8
  return response
9
 
10
  # Date for the index last updated
11
  last_updated_date = datetime.now().strftime("%B %d, %Y")
12
 
13
- # Interface components
14
- title_block = gr.HTML("""
15
- <h2>FindMyPlot</h2>
16
- <p>Find a plot within experimental high energy physics collider results.<br>
17
- Index last updated {}.</p>
18
- """.format(last_updated_date))
19
-
20
- query_input = gr.Textbox(label="Search", placeholder="Enter your query here...", lines=2)
21
- collections = gr.CheckboxGroup(choices=["ATLAS_Conference_Notes", "ATLAS_Papers", "CMS_Papers", "ATLAS_PUB_Notes", "CMS_Physics_Analysis_Summaries"],
22
- label="Advanced Options: Select Collections",
23
- value=["ATLAS_Conference_Notes", "ATLAS_Papers"], visible=False) # By default, not showing advanced options
24
-
25
- # Defining the function that will toggle visibility of the advanced options
26
- def toggle_advanced_options(is_clicked):
27
- collections.visible = not collections.visible
28
- return gr.update(visible=collections.visible)
29
-
30
- advanced_options_button = gr.Button("Advanced Options", elem_id="advanced_options_button")
31
- advanced_options_button.click(fn=toggle_advanced_options, inputs=advanced_options_button, outputs=collections)
32
-
33
- # Binding the input, options, and the search function together
34
- output_chat = gr.Textbox(label="Results", lines=6, interactive=True, elem_id="results_area")
35
- search_button = gr.Button("Search")
36
- search_interface = gr.Interface(fn=search, inputs=[query_input, collections], outputs=output_chat)
37
 
38
  app = gr.Blocks()
39
 
40
  with app:
41
- gr.Row(title_block)
42
- gr.Row(gr.Column(query_input, advanced_options_button, collections, search_button, output_chat))
43
-
44
- # Styling
45
- app.css = """
46
- #results_area { margin-top: 20px; }
47
- #advanced_options_button { margin-top: 20px; margin-bottom: 20px; }
48
- """
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
- # Launch the app
51
  if __name__ == "__main__":
52
  app.launch()
 
2
  from datetime import datetime
3
 
4
  def search(query, collections):
5
+ # Placeholder function for custom RAG integration
 
6
  response = f"Results for query: {query} from collections: {', '.join(collections)}"
7
  return response
8
 
9
  # Date for the index last updated
10
  last_updated_date = datetime.now().strftime("%B %d, %Y")
11
 
12
+ # Define the function to toggle the visibility of advanced options
13
+ def toggle_advanced_options(is_clicked, collections_visibility):
14
+ return not collections_visibility
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  app = gr.Blocks()
17
 
18
  with app:
19
+ gr.Markdown(f"### FindMyPlot\nFind a plot within experimental high energy physics collider results.\nIndex last updated {last_updated_date}.")
20
+
21
+ query_input = gr.Textbox(label="Search", placeholder="Enter your query here...", lines=2)
22
+ collections = gr.CheckboxGroup(choices=["ATLAS_Conference_Notes", "ATLAS_Papers", "CMS_Papers", "ATLAS_PUB_Notes", "CMS_Physics_Analysis_Summaries"],
23
+ label="Select Collections",
24
+ value=["ATLAS_Conference_Notes", "ATLAS_Papers"],
25
+ visible=False) # Start hidden
26
+
27
+ advanced_options_button = gr.Button("Advanced Options")
28
+ search_button = gr.Button("Search")
29
+ output_chat = gr.Textbox(label="Results", lines=6, interactive=True)
30
+
31
+ advanced_options_button.click(fn=toggle_advanced_options,
32
+ inputs=advanced_options_button,
33
+ outputs=collections,
34
+ _js="(is_clicked, collections_visibility) => [!collections_visibility]")
35
+
36
+ search_button.click(fn=search,
37
+ inputs=[query_input, collections],
38
+ outputs=output_chat)
39
 
 
40
  if __name__ == "__main__":
41
  app.launch()