Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,40 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def register_tool(tool_data):
|
5 |
# Send a POST request to register the tool
|
6 |
response = requests.post("https://huggingface.co/chat/tools/new", json=tool_data)
|
@@ -31,4 +65,9 @@ demo = gr.Interface(
|
|
31 |
inputs=inputs, # Updated line
|
32 |
outputs=outputs # You can use gr.Textbox or other components as needed
|
33 |
)
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
def calculator(num1, operation, num2):
|
5 |
+
if operation == "add":
|
6 |
+
return num1 + num2
|
7 |
+
elif operation == "subtract":
|
8 |
+
return num1 - num2
|
9 |
+
elif operation == "multiply":
|
10 |
+
return num1 * num2
|
11 |
+
elif operation == "divide":
|
12 |
+
return num1 / num2
|
13 |
+
|
14 |
+
with gr.Blocks() as demo:
|
15 |
+
with gr.Row():
|
16 |
+
with gr.Column():
|
17 |
+
num_1 = gr.Number(value=4)
|
18 |
+
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
|
19 |
+
num_2 = gr.Number(value=0)
|
20 |
+
submit_btn = gr.Button(value="Calculate")
|
21 |
+
with gr.Column():
|
22 |
+
result = gr.Number()
|
23 |
+
|
24 |
+
submit_btn.click(
|
25 |
+
calculator, inputs=[num_1, operation, num_2], outputs=[result], api_name=False
|
26 |
+
)
|
27 |
+
examples = gr.Examples(
|
28 |
+
examples=[
|
29 |
+
[5, "add", 3],
|
30 |
+
[4, "divide", 2],
|
31 |
+
[-4, "multiply", 2.5],
|
32 |
+
[0, "subtract", 1.2],
|
33 |
+
],
|
34 |
+
inputs=[num_1, operation, num_2],
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
def register_tool(tool_data):
|
39 |
# Send a POST request to register the tool
|
40 |
response = requests.post("https://huggingface.co/chat/tools/new", json=tool_data)
|
|
|
65 |
inputs=inputs, # Updated line
|
66 |
outputs=outputs # You can use gr.Textbox or other components as needed
|
67 |
)
|
68 |
+
|
69 |
+
|
70 |
+
if __name__ == "__main__":
|
71 |
+
|
72 |
+
|
73 |
+
demo.launch(show_api=True, share=False)
|