Fix Gradio interface with Blocks layout and improve response parsing
Browse files- Replaced problematic gr.Interface with gr.Blocks for multiple functions
- Added tabbed interface for Stock/ETF Info and Ask Madam functions
- Improved ask_madam response parsing to extract 'response' field
- Fixed component configuration issues for MCP server compatibility
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
app.py
CHANGED
@@ -61,14 +61,23 @@ def ask_madam(question):
|
|
61 |
}
|
62 |
)
|
63 |
response.raise_for_status()
|
64 |
-
return response.text
|
65 |
except requests.exceptions.RequestException as e:
|
66 |
return f"Error communicating with Madam API: {str(e)}"
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
demo.launch(mcp_server=True)
|
|
|
61 |
}
|
62 |
)
|
63 |
response.raise_for_status()
|
64 |
+
return eval(response.text).get('response', 'No response from Madam API')
|
65 |
except requests.exceptions.RequestException as e:
|
66 |
return f"Error communicating with Madam API: {str(e)}"
|
67 |
|
68 |
+
with gr.Blocks() as demo:
|
69 |
+
with gr.Tab("Stock/ETF Info"):
|
70 |
+
language_input = gr.Textbox(label="Language (zh-tw, zh-cn, other)")
|
71 |
+
category_input = gr.Textbox(label="Category (US Stock, US ETF, TW ETF)")
|
72 |
+
ticker_input = gr.Textbox(label="Ticker Symbol")
|
73 |
+
stock_output = gr.Textbox(label="MacroMicro URL")
|
74 |
+
stock_btn = gr.Button("Get URL")
|
75 |
+
stock_btn.click(get_stock_etf_info_url, inputs=[language_input, category_input, ticker_input], outputs=stock_output)
|
76 |
+
|
77 |
+
with gr.Tab("Ask Madam"):
|
78 |
+
question_input = gr.Textbox(label="Question")
|
79 |
+
madam_output = gr.Textbox(label="Answer")
|
80 |
+
madam_btn = gr.Button("Ask Madam", interactive=False)
|
81 |
+
madam_btn.click(ask_madam, inputs=question_input, outputs=madam_output)
|
82 |
+
|
83 |
demo.launch(mcp_server=True)
|