signup / app.py
nagasurendra's picture
Create app.py
45983a5 verified
import gradio as gr
import pandas as pd
import os
# Define a function to save details to Excel
def save_to_excel(name, email, phone, address):
# File path for Excel file
file_path = "stored_details.xlsx"
# Check if the Excel file exists
if os.path.exists(file_path):
# Load existing file
df = pd.read_excel(file_path)
else:
# Create a new DataFrame if file doesn't exist
df = pd.DataFrame(columns=["Name", "Email", "Phone", "Address"])
# Append new details
new_entry = {"Name": name, "Email": email, "Phone": phone, "Address": address}
df = df.append(new_entry, ignore_index=True)
# Save the updated DataFrame back to Excel
df.to_excel(file_path, index=False, engine='openpyxl')
return "Details saved successfully!", file_path
# Gradio Interface
def download_excel():
# Return the path to the Excel file for download
return "stored_details.xlsx"
# Define the Gradio components
with gr.Blocks() as demo:
gr.Markdown("# Save Details to Excel")
name = gr.Textbox(label="Name")
email = gr.Textbox(label="Email")
phone = gr.Textbox(label="Phone")
address = gr.Textbox(label="Address")
submit_button = gr.Button("Save to Excel")
message = gr.Label()
download_button = gr.File(label="Download Excel File")
# Connect components
submit_button.click(save_to_excel, [name, email, phone, address], [message, download_button])
# Launch the Gradio app
demo.launch()