Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Step 1: Install Gradio and FPDF (No need to install in Hugging Face Spaces if using requirements.txt)
|
2 |
+
# !pip install gradio fpdf
|
3 |
+
|
4 |
+
# Step 2: Import necessary libraries
|
5 |
+
import gradio as gr
|
6 |
+
from fpdf import FPDF
|
7 |
+
|
8 |
+
# Step 3: Define a function to handle form submission and generate a PDF file
|
9 |
+
def submit_form(name, whatsapp, membership, protest):
|
10 |
+
# Create a PDF object
|
11 |
+
pdf = FPDF()
|
12 |
+
pdf.add_page()
|
13 |
+
pdf.set_font("Arial", size=12)
|
14 |
+
|
15 |
+
# Add form data in formal format
|
16 |
+
pdf.cell(200, 10, txt=f"Name: {'_'*50}", ln=True)
|
17 |
+
pdf.cell(200, 10, txt=f"WhatsApp Mobile No: {'_'*40}", ln=True)
|
18 |
+
pdf.cell(200, 10, txt=f"Are you want a member of YEP?: {'_'*30}", ln=True)
|
19 |
+
pdf.cell(200, 10, txt=f"Did you join the protest?: {'_'*35}", ln=True)
|
20 |
+
|
21 |
+
# Now add the user's input
|
22 |
+
pdf.ln(10) # Line break for spacing
|
23 |
+
pdf.cell(200, 10, txt=f"Name: {name}", ln=True)
|
24 |
+
pdf.cell(200, 10, txt=f"WhatsApp Mobile No: {whatsapp}", ln=True)
|
25 |
+
pdf.cell(200, 10, txt=f"Membership of YEP: {membership}", ln=True)
|
26 |
+
pdf.cell(200, 10, txt=f"Participation in Protest: {protest}", ln=True)
|
27 |
+
|
28 |
+
# Save the PDF
|
29 |
+
pdf_output_path = "/tmp/form_data.pdf" # Save in a temporary directory on Hugging Face Space
|
30 |
+
pdf.output(pdf_output_path)
|
31 |
+
|
32 |
+
# Return the path to the generated PDF for download
|
33 |
+
return pdf_output_path
|
34 |
+
|
35 |
+
# Step 4: Set up the Gradio interface
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("## Submit Your Information")
|
38 |
+
|
39 |
+
# Agenda of YEP
|
40 |
+
gr.Markdown("""
|
41 |
+
### Young Engineers Pakistan (YEP) Agenda
|
42 |
+
1. Grant rights to Young Engineers in the Governing Body.
|
43 |
+
2. Provide detailed transparency of PEC expenses, showing how thousands of rupees are utilized by PEC employees.
|
44 |
+
3. Immediately withdraw all illegal notifications and promotions.
|
45 |
+
4. Grant Young Engineers the right to resign from and rejoin any company.
|
46 |
+
5. Provide Young Engineers with opportunities for internships, innovation, and access to an Incubation Center.
|
47 |
+
6. The new PEC building should be used as an Incubation Center, not for renting purposes.
|
48 |
+
""")
|
49 |
+
|
50 |
+
name = gr.Textbox(label="Name", placeholder="Enter your name here")
|
51 |
+
whatsapp = gr.Textbox(label="WhatsApp Mobile No.", placeholder="Enter your WhatsApp mobile number here")
|
52 |
+
membership = gr.Dropdown(label="Are you a member of YEP?", choices=["Yes", "No"], value="No")
|
53 |
+
protest = gr.Dropdown(label="Did you join the protest?", choices=["Yes", "No"], value="No")
|
54 |
+
|
55 |
+
submit = gr.Button("Submit")
|
56 |
+
pdf_output = gr.File(label="Download your PDF")
|
57 |
+
|
58 |
+
# Link the button to the function
|
59 |
+
submit.click(submit_form, inputs=[name, whatsapp, membership, protest], outputs=pdf_output)
|
60 |
+
|
61 |
+
# Step 5: Launch the Gradio app
|
62 |
+
demo.launch()
|