Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +17 -68
Gradio_UI.py
CHANGED
|
@@ -1,73 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from smolagents import CodeAgent
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 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()`
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from smolagents import CodeAgent
|
| 3 |
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from app import get_weather # Ensure this function is correctly imported from the main script
|
| 6 |
+
|
| 7 |
+
def weather_interface(city):
|
| 8 |
+
return get_weather(city)
|
| 9 |
+
|
| 10 |
+
# Define Gradio UI components
|
| 11 |
+
with gr.Blocks() as demo:
|
| 12 |
+
gr.Markdown("# Weather Information App")
|
| 13 |
+
city = gr.Textbox(label="Enter City Name")
|
| 14 |
+
get_weather_button = gr.Button("Get Weather")
|
| 15 |
+
output = gr.Textbox(label="Weather Details")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
get_weather_button.click(weather_interface, inputs=[city], outputs=output)
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
demo.launch()
|
| 21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|