import gradio as gr import pandas as pd def save_to_excel(Name, Email, Comment): data = {'Name': [Name], 'Email': [Email], 'Message': [Comment]} df = pd.DataFrame(data) # Read in existing sheet if it exists, or create an empty DataFrame try: existing_df = pd.read_excel('Contacts.xlsx', sheet_name='ContactDetails') except: existing_df = pd.DataFrame() # Combine existing sheet with new data combined_df = pd.concat([existing_df, df], ignore_index=True) # Write combined data to new Excel file writer = pd.ExcelWriter('Contacts.xlsx', engine='openpyxl', mode='w') combined_df.to_excel(writer, sheet_name='ContactDetails', index=False) writer.save() return 'Thank you for contacting us!' form = gr.Interface(fn=save_to_excel, inputs=[gr.inputs.Textbox(label="Name"), gr.inputs.Textbox(label="Email"), gr.inputs.Textbox(lines=7, label="Comment")], outputs=[], title='Leave a Comment or Request Demo', theme=gr.themes.Default(primary_hue="slate")) form.launch()