Abu1998 commited on
Commit
0f3950d
·
verified ·
1 Parent(s): 1a78ead

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Append new data
27
+ new_row = {
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
+ df = df.append(new_row, ignore_index=True)
41
+ df.to_csv(STORAGE_PATH, index=False) # Save to CSV
42
+ return f"Data saved successfully for Appointment {appointment}!"
43
+
44
+ # Define Gradio interface
45
+ with gr.Blocks() as app:
46
+ gr.Markdown("# Appointment Data Storage Application")
47
+ appointment_timing = gr.Textbox(label="Appointment Timing")
48
+ services = gr.Dropdown(
49
+ label="Services",
50
+ choices=["Full arm Rica", "Full leg", "Underarms", "Eyebrow", "Upper lips"],
51
+ multiselect=True
52
+ )
53
+ products = gr.Textbox(label="Products")
54
+ contact = gr.Textbox(label="Contact")
55
+ customer_name = gr.Textbox(label="Customer Name")
56
+ rating = gr.Radio(label="Rating", choices=["Very good", "Good", "Normal", "Bad", "Too bad"])
57
+ location = gr.Textbox(label="Location")
58
+ key_points = gr.Textbox(label="Key-points")
59
+ price = gr.Dropdown(label="Price", choices=["999", "1499", "2499", "3499", "4499"])
60
+ submit_button = gr.Button("Submit")
61
+ output = gr.Textbox(label="Output")
62
+
63
+ submit_button.click(
64
+ save_to_csv,
65
+ inputs=[
66
+ appointment_timing, services, products, contact, customer_name, rating, location, key_points, price
67
+ ],
68
+ outputs=output
69
+ )
70
+
71
+ # Launch the application
72
+ app.launch()