boi-doingthings commited on
Commit
ba4cfbf
1 Parent(s): bfbe667

added more fields

Browse files
Files changed (1) hide show
  1. app.py +20 -19
app.py CHANGED
@@ -1,28 +1,29 @@
1
  import gradio as gr
 
2
 
3
- # Define a function that takes the input parameters and returns a result
4
- def analyze_person(sex, age, height, weight):
5
- # You can perform any processing or analysis here based on the input parameters
6
- # For this example, we'll simply return the input parameters as a dictionary
7
- result = {
8
- "Sex": sex,
9
- "Age": age,
10
- "Height": height,
11
- "Weight": weight
12
  }
13
- return result
14
 
15
- # Define the Gradio interface
16
  iface = gr.Interface(
17
- fn=analyze_person, # Function to call with input parameters
18
- inputs=[
19
- gr.inputs.Radio(["Male", "Female"], label="Sex"), # Radio button for sex
20
- gr.inputs.Number(label="Age"), # Numeric input for age
21
- gr.inputs.Number(label="Height (cm)"), # Numeric input for height
22
- gr.inputs.Number(label="Weight (kg)") # Numeric input for weight
 
23
  ],
24
- outputs=gr.outputs.JSON() # Display the result as JSON
25
  )
26
 
27
- # Start the Gradio interface
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()