gfacini commited on
Commit
c65511c
·
verified ·
1 Parent(s): 46136ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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()