MaroofTechSorcerer commited on
Commit
0794d44
·
verified ·
1 Parent(s): 80e793e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # First, make sure you have gradio installed:
2
+ # pip install gradio
3
+
4
+ import gradio as gr
5
+
6
+ def process_form(name, age, is_student):
7
+ """
8
+ This function takes the form inputs and processes them.
9
+ It returns a formatted string that will be displayed as the output.
10
+ """
11
+ # Determine the student status string based on the checkbox value
12
+ student_status = "a student" if is_student else "not a student"
13
+
14
+ # Create the output message
15
+ output_message = f"Hello, {name}! You are {age} years old and you are {student_status}."
16
+
17
+ return output_message
18
+
19
+ # We use gr.Blocks() for more layout control, which is common for forms.
20
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
21
+ # Add a title using Markdown
22
+ gr.Markdown("# Simple User Information Form")
23
+ gr.Markdown("Enter your details below and click 'Submit'.")
24
+
25
+ # Define the input components for the form
26
+ with gr.Row():
27
+ name_input = gr.Textbox(label="Name", placeholder="e.g., Jane Doe")
28
+ age_input = gr.Number(label="Age", value=25) # Set a default value
29
+
30
+ student_checkbox = gr.Checkbox(label="Are you a student?")
31
+
32
+ # Define the submit button
33
+ submit_button = gr.Button("Submit")
34
+
35
+ # Define the output component where the result will be displayed
36
+ output_text = gr.Text(label="Greeting Message")
37
+
38
+ # Define the action when the submit button is clicked.
39
+ # It calls the 'process_form' function with the values from the input components
40
+ # and places the return value into the 'output_text' component.
41
+ submit_button.click(
42
+ fn=process_form,
43
+ inputs=[name_input, age_input, student_checkbox],
44
+ outputs=output_text
45
+ )
46
+
47
+ # Launch the Gradio app
48
+ if __name__ == "__main__":
49
+ demo.launch()