Spaces:
Sleeping
Sleeping
boi-doingthings
commited on
Commit
•
ba4cfbf
1
Parent(s):
bfbe667
added more fields
Browse files
app.py
CHANGED
@@ -1,28 +1,29 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
#
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"Weight": weight
|
12 |
}
|
13 |
-
return
|
14 |
|
15 |
-
#
|
16 |
iface = gr.Interface(
|
17 |
-
|
18 |
-
|
19 |
-
gr.
|
20 |
-
gr.
|
21 |
-
gr.
|
22 |
-
gr.
|
|
|
23 |
],
|
24 |
-
|
25 |
)
|
26 |
|
27 |
-
#
|
28 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
|
4 |
+
# Function to collect inputs and return a JSON
|
5 |
+
def create_json(sex, age, weight, height, diet):
|
6 |
+
data = {
|
7 |
+
"sex": sex,
|
8 |
+
"age": age,
|
9 |
+
"weight": weight,
|
10 |
+
"height": height,
|
11 |
+
"dietary preference": diet,
|
|
|
12 |
}
|
13 |
+
return json.dumps(data, indent=4) # Convert the dictionary to a JSON string with indentation
|
14 |
|
15 |
+
# Create Gradio UI with input components for sex, age, weight, height, and diet
|
16 |
iface = gr.Interface(
|
17 |
+
create_json,
|
18 |
+
[
|
19 |
+
gr.components.Radio(["Male", "Female", "Other"], label="Sex"),
|
20 |
+
gr.components.Slider(minimum=0, maximum=120, default=25, label="Age"),
|
21 |
+
gr.components.Slider(minimum=0, maximum=200, default=65, label="Weight (kg)"),
|
22 |
+
gr.components.Slider(minimum=0, maximum=250, default=170, label="Height (cm)"),
|
23 |
+
gr.components.Dropdown(["Veg", "Non-Veg", "Vegan"], label="Dietary Preference"),
|
24 |
],
|
25 |
+
gr.components.JSON(label="Output JSON")
|
26 |
)
|
27 |
|
28 |
+
# Launch the Gradio app
|
29 |
iface.launch()
|