import gradio as gr
# Backend function
def process_data(name, age):
if not name or not age:
return "Please provide both name and age."
return f"Hello {name}! You are {age} years old."
# HTML for the form
custom_html = """
"""
# JavaScript for handling submission
custom_script = """
"""
# Gradio Interface for the backend
backend_interface = gr.Interface(
fn=process_data,
inputs=["text", "text"],
outputs="text"
)
# Main Gradio app
with gr.Blocks() as app:
with gr.Row():
gr.HTML("Interactive Form Example
")
with gr.Row():
gr.HTML(custom_html)
with gr.Row():
gr.HTML(custom_script)
# Launching app and backend interface
app.queue() # Allow async queue
backend_interface.launch() # Ensure backend is running