Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| class GradioUI: | |
| def __init__(self, agent,time_tool, currency_tool): | |
| self.agent = agent | |
| self.time_tool = time_tool # Store the time tool passed from app.py | |
| self.currency_tool = currency_tool # Store the currency tool passed from app.py | |
| self.ui = self._build_ui() | |
| def _process_input(self, user_input): | |
| print(f"Processing input: {user_input}") | |
| location = user_input.strip() | |
| if not location: | |
| return "Please mention a location." | |
| time_result = self.time_tool(location) | |
| currency_result = self.currency_tool(location) | |
| print(f"Time result: {time_result}") | |
| print(f"Currency result: {currency_result}") | |
| if "not found" in time_result.lower() or "not found" in currency_result.lower() or "error" in time_result.lower() or "error" in currency_result.lower(): | |
| return "Please mention a location." | |
| time_part = time_result.split(": ")[1] if ": " in time_result else time_result | |
| currency_part = currency_result.split(": ")[1] if ": " in currency_result else currency_result | |
| return f"Time at {location} now is {time_part}, currency is {currency_part}." | |
| def _build_ui(self): | |
| with gr.Blocks(title="Time and Currency Agent") as app: | |
| gr.Markdown("## Input a location") | |
| input_box = gr.Textbox(label="Enter a location", placeholder="Type here...") | |
| output_box = gr.Textbox(label="Result", interactive=False) | |
| submit_btn = gr.Button("Submit") | |
| submit_btn.click(fn=self._process_input, inputs=input_box, outputs=output_box) | |
| input_box.submit(fn=self._process_input, inputs=input_box, outputs=output_box) | |
| return app | |
| def launch(self): | |
| self.ui.launch(server_name="0.0.0.0", server_port=7860) |