Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,82 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
df.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
4 |
+
import os
|
5 |
|
6 |
+
# Path for local storage on Hugging Face Space
|
7 |
+
STORAGE_PATH = "appointments.csv"
|
8 |
|
9 |
+
# Check if the storage file exists; if not, create it
|
10 |
+
if not os.path.exists(STORAGE_PATH):
|
11 |
+
df = pd.DataFrame(columns=[
|
12 |
+
"Date", "Appointment", "Appointment Timing", "Services", "Products",
|
13 |
+
"Contact", "Customer Name", "Rating", "Location", "Key-points", "Price"
|
14 |
+
])
|
15 |
+
df.to_csv(STORAGE_PATH, index=False)
|
16 |
+
|
17 |
+
# Function to save data to CSV
|
18 |
+
def save_to_csv(appointment_timing, services, products, contact, customer_name, rating, location, key_points, price):
|
19 |
+
# Load existing data
|
20 |
+
df = pd.read_csv(STORAGE_PATH)
|
21 |
+
|
22 |
+
# Auto-detect current date and appointment number
|
23 |
+
date = datetime.now().strftime("%Y-%m-%d")
|
24 |
+
appointment = len(df) + 1 # Generate appointment ID
|
25 |
+
|
26 |
+
# Create a new row as a DataFrame
|
27 |
+
new_row = pd.DataFrame([{
|
28 |
+
"Date": date,
|
29 |
+
"Appointment": appointment,
|
30 |
+
"Appointment Timing": appointment_timing,
|
31 |
+
"Services": services,
|
32 |
+
"Products": products,
|
33 |
+
"Contact": contact,
|
34 |
+
"Customer Name": customer_name,
|
35 |
+
"Rating": rating,
|
36 |
+
"Location": location,
|
37 |
+
"Key-points": key_points,
|
38 |
+
"Price": price
|
39 |
+
}])
|
40 |
+
|
41 |
+
# Concatenate the new row with the existing DataFrame
|
42 |
+
df = pd.concat([df, new_row], ignore_index=True)
|
43 |
+
df.to_csv(STORAGE_PATH, index=False) # Save the updated DataFrame to the CSV file
|
44 |
+
return f"Data saved successfully for Appointment {appointment}!"
|
45 |
+
|
46 |
+
# Function to provide the download file
|
47 |
+
def get_csv_file():
|
48 |
+
return STORAGE_PATH
|
49 |
+
|
50 |
+
# Define Gradio interface
|
51 |
+
with gr.Blocks() as app:
|
52 |
+
gr.Markdown("# Appointment Data Storage Application")
|
53 |
+
appointment_timing = gr.Textbox(label="Appointment Timing")
|
54 |
+
services = gr.Dropdown(
|
55 |
+
label="Services",
|
56 |
+
choices=["Full arm Rica", "Full leg", "Underarms", "Eyebrow", "Upper lips"],
|
57 |
+
multiselect=True
|
58 |
+
)
|
59 |
+
products = gr.Textbox(label="Products")
|
60 |
+
contact = gr.Textbox(label="Contact")
|
61 |
+
customer_name = gr.Textbox(label="Customer Name")
|
62 |
+
rating = gr.Radio(label="Rating", choices=["Very good", "Good", "Normal", "Bad", "Too bad"])
|
63 |
+
location = gr.Textbox(label="Location")
|
64 |
+
key_points = gr.Textbox(label="Key-points")
|
65 |
+
price = gr.Dropdown(label="Price", choices=["999", "1499", "2499", "3499", "4499"])
|
66 |
+
submit_button = gr.Button("Submit")
|
67 |
+
output = gr.Textbox(label="Output")
|
68 |
+
download_button = gr.File(label="Download Appointments Data", value=STORAGE_PATH)
|
69 |
+
|
70 |
+
submit_button.click(
|
71 |
+
save_to_csv,
|
72 |
+
inputs=[
|
73 |
+
appointment_timing, services, products, contact, customer_name, rating, location, key_points, price
|
74 |
+
],
|
75 |
+
outputs=output
|
76 |
+
)
|
77 |
+
|
78 |
+
# Add a file download button
|
79 |
+
download_button.render()
|
80 |
+
|
81 |
+
# Launch the application
|
82 |
+
app.launch(share=True)
|