21spl commited on
Commit
128c031
·
verified ·
1 Parent(s): ef06b26

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +61 -56
Gradio_UI.py CHANGED
@@ -1,68 +1,73 @@
1
  import gradio as gr
 
2
 
3
  class GradioUI:
4
- def __init__(self, agent):
5
- self.agent = agent
6
- self.interface = self._create_interface()
7
-
8
- def _create_interface(self):
9
- # Define custom CSS to hide the resize arrows and style the output
10
- custom_css = """
11
- /* Hide the resize arrows */
12
- .output-container .svelte-1g9btlg { display: none !important; }
13
 
14
- /* Style the output panel */
15
- #output-panel {
16
- height: 400px !important; /* Fixed height */
17
- overflow-y: auto; /* Add scrollbar if content overflows */
18
- border: 1px solid #ccc; /* Add a subtle border */
19
- border-radius: 5px; /* Rounded corners */
20
- padding: 10px; /* Inner padding */
21
- background-color: #f9f9f9; /* Light background */
22
- }
23
 
24
- /* Style the links */
25
- #output-panel a {
26
- color: #1a73e8; /* Google-blue link color */
27
- text-decoration: none; /* Remove underline */
28
- font-weight: bold; /* Bold links */
29
- }
30
- #output-panel a:hover {
31
- text-decoration: underline; /* Underline on hover */
32
- }
33
 
34
- /* Style the list items */
35
- #output-panel ul {
36
- list-style-type: none; /* Remove default bullets */
37
- padding-left: 0; /* Remove default padding */
38
- }
39
- #output-panel li {
40
- margin-bottom: 10px; /* Space between list items */
41
- }
42
  """
43
-
44
- with gr.Blocks(title="Landsat Image Fetcher", css=custom_css) as demo:
45
- gr.Markdown("# Landsat Image Fetcher")
46
- gr.Markdown("Enter coordinates and a time range to fetch Landsat images from USGS.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  with gr.Row():
48
- with gr.Column():
49
- lat_min = gr.Number(label="Min Latitude", value=37.75)
50
- lon_min = gr.Number(label="Min Longitude", value=-122.35)
51
- lat_max = gr.Number(label="Max Latitude", value=37.85)
52
- lon_max = gr.Number(label="Max Longitude", value=-122.25)
53
- start_date = gr.Textbox(label="Start Date (YYYY-MM-DD)", value="2023-01-01")
54
- end_date = gr.Textbox(label="End Date (YYYY-MM-DD)", value="2023-12-31")
55
- submit_btn = gr.Button("Fetch Images")
56
- with gr.Column():
57
- output = gr.HTML(label="Download Links", elem_id="output-panel")
 
 
 
 
 
 
 
 
 
 
 
 
58
  submit_btn.click(
59
- fn=lambda lm, ln, lx, lo, sd, ed: self.agent.run(
60
- f"fetch_landsat_image({lm}, {ln}, {lx}, {lo}, '{sd}', '{ed}')"
61
- ),
62
- inputs=[lat_min, lon_min, lat_max, lon_max, start_date, end_date],
63
  outputs=output
64
  )
65
- return demo
 
 
66
 
67
- def launch(self, **kwargs):
68
- self.interface.launch(**kwargs)
 
1
  import gradio as gr
2
+ from smolagents import CodeAgent
3
 
4
  class GradioUI:
5
+ def __init__(self, agent: CodeAgent):
6
+ """Initialize the Gradio UI with the provided agent.
 
 
 
 
 
 
 
7
 
8
+ Args:
9
+ agent: An instance of CodeAgent from smolagents.
10
+ """
11
+ self.agent = agent
12
+
13
+ def run_agent(self, player_name: str, role: str) -> str:
14
+ """Run the agent with the cricketer analysis tool.
 
 
15
 
16
+ Args:
17
+ player_name: The name of the cricketer to analyze.
18
+ role: The role of the cricketer (e.g., 'batter', 'bowler').
 
 
 
 
 
 
19
 
20
+ Returns:
21
+ A string with the analysis result or an error message.
 
 
 
 
 
 
22
  """
23
+ # Construct the query for the agent
24
+ query = f"Analyze the form of cricketer '{player_name}' as a '{role}'"
25
+ try:
26
+ # Execute the agent's run method with the query
27
+ response = self.agent.run(query)
28
+ return response
29
+ except Exception as e:
30
+ return f"Error running analysis: {str(e)}"
31
+
32
+ def launch(self):
33
+ """Launch the Gradio interface."""
34
+ # Define the UI layout using Gradio Blocks
35
+ with gr.Blocks(title="Cricketer Form Analyzer") as interface:
36
+ # Header
37
+ gr.Markdown("# Cricketer Form Analyzer")
38
+ gr.Markdown("Enter a cricketer's name and select their role to analyze their recent form and career stats.")
39
+
40
+ # Input section
41
  with gr.Row():
42
+ player_input = gr.Textbox(
43
+ label="Player Name",
44
+ placeholder="e.g., Virat Kohli",
45
+ lines=1
46
+ )
47
+ role_input = gr.Dropdown(
48
+ choices=["batter", "bowler", "wicket_keeper", "fielder"],
49
+ label="Role",
50
+ value="batter" # Default selection
51
+ )
52
+
53
+ # Submit button
54
+ submit_btn = gr.Button("Analyze")
55
+
56
+ # Output section
57
+ output = gr.Textbox(
58
+ label="Analysis Result",
59
+ lines=10,
60
+ placeholder="Analysis will appear here..."
61
+ )
62
+
63
+ # Connect the button to the run_agent function
64
  submit_btn.click(
65
+ fn=self.run_agent,
66
+ inputs=[player_input, role_input],
 
 
67
  outputs=output
68
  )
69
+
70
+ # Launch the interface
71
+ interface.launch()
72
 
73
+ # Note: This is imported and used in app.py as `GradioUI(agent).launch()`