Vasanth M
commited on
Commit
·
7730595
1
Parent(s):
87eaaae
fix
Browse files
app.py
CHANGED
@@ -42,6 +42,22 @@ def convert_temperature(temp: str, unit: str) -> dict[str, str]:
|
|
42 |
except ValueError:
|
43 |
return {"celsius": "Invalid", "fahrenheit": "Invalid", "kelvin": "Invalid"}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Define the Gradio interface
|
46 |
with gr.Blocks() as app:
|
47 |
gr.Markdown("# Temperature Converter")
|
@@ -60,11 +76,10 @@ with gr.Blocks() as app:
|
|
60 |
kelvin_output = gr.Textbox(label="Kelvin")
|
61 |
|
62 |
convert_button.click(
|
63 |
-
fn=convert_temperature,
|
64 |
inputs=[temp_input, unit_dropdown],
|
65 |
outputs=[celsius_output, fahrenheit_output, kelvin_output],
|
66 |
-
api_name="/convert_temperature"
|
67 |
-
_js="result => [result.celsius, result.fahrenheit, result.kelvin]"
|
68 |
)
|
69 |
|
70 |
# Launch the app with MCP server enabled
|
|
|
42 |
except ValueError:
|
43 |
return {"celsius": "Invalid", "fahrenheit": "Invalid", "kelvin": "Invalid"}
|
44 |
|
45 |
+
def map_output(result: dict[str, str]) -> list[str]:
|
46 |
+
"""
|
47 |
+
Maps the dictionary output of convert_temperature to a list for Gradio outputs.
|
48 |
+
|
49 |
+
Args:
|
50 |
+
result (dict[str, str]): The dictionary containing temperature values.
|
51 |
+
|
52 |
+
Returns:
|
53 |
+
list[str]: A list of temperature values in order [celsius, fahrenheit, kelvin].
|
54 |
+
"""
|
55 |
+
return [result["celsius"], result["fahrenheit"], result["kelvin"]]
|
56 |
+
|
57 |
+
# Debug prints
|
58 |
+
print("Gradio Version:", gr.__version__)
|
59 |
+
print("MCP Server Enabled:", gr.mcp_server_enabled())
|
60 |
+
|
61 |
# Define the Gradio interface
|
62 |
with gr.Blocks() as app:
|
63 |
gr.Markdown("# Temperature Converter")
|
|
|
76 |
kelvin_output = gr.Textbox(label="Kelvin")
|
77 |
|
78 |
convert_button.click(
|
79 |
+
fn=lambda temp, unit: map_output(convert_temperature(temp, unit)),
|
80 |
inputs=[temp_input, unit_dropdown],
|
81 |
outputs=[celsius_output, fahrenheit_output, kelvin_output],
|
82 |
+
api_name="/convert_temperature"
|
|
|
83 |
)
|
84 |
|
85 |
# Launch the app with MCP server enabled
|