Sw1ft0 commited on
Commit
7273bff
·
0 Parent(s):

Add initial files

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +0 -0
  3. app.py +63 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ testing_files/
README.md ADDED
File without changes
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ # Store the uploaded dataframe in memory
5
+ dataframes = {}
6
+
7
+ def upload_excel(file):
8
+ if file is None:
9
+ return "Please upload an Excel file first."
10
+ try:
11
+ df = pd.read_excel(file.name)
12
+ dataframes["df"] = df
13
+ preview = df.head().to_string()
14
+ return f"✅ File uploaded successfully! Here are the first rows:\n\n{preview}"
15
+ except Exception as e:
16
+ return f"❌ Error reading Excel file: {e}"
17
+
18
+ def chat_agent(message, history):
19
+ if "df" not in dataframes:
20
+ return "Please upload an Excel file first."
21
+
22
+ df = dataframes["df"]
23
+
24
+ # Very simple “question routing” demo
25
+ message_lower = message.lower()
26
+
27
+ if "otb" in message_lower and "revenue" in message_lower and "august" in message_lower:
28
+ try:
29
+ otb_august = df.loc[df['Month'] == 'August', 'OTB Revenue'].values[0]
30
+ stly_august = df.loc[df['Month'] == 'August', 'STLY Revenue'].values[0]
31
+ return f"OTB Revenue (August): {otb_august}\nSTLY Revenue (August): {stly_august}"
32
+ except:
33
+ return "I couldn't find OTB Revenue data for August in your file."
34
+
35
+ elif "occupancy" in message_lower and "august" in message_lower:
36
+ try:
37
+ occ_actual = df.loc[df['Month'] == 'August', 'Occupancy %'].values[0]
38
+ occ_target = df.loc[df['Month'] == 'August', 'Budgeted Occupancy %'].values[0]
39
+ if occ_actual >= occ_target:
40
+ return f"Occupancy for August is {occ_actual}% vs target {occ_target}% ✅ On track!"
41
+ else:
42
+ return f"Occupancy for August is {occ_actual}% vs target {occ_target}% ⚠️ Might not meet target."
43
+ except:
44
+ return "I couldn't find occupancy data for August in your file."
45
+
46
+ else:
47
+ return "Sorry, I can only answer about OTB Revenue and Occupancy for now. (You can extend me with more rules!)"
48
+
49
+
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("# 📊 OtelAI Excel Q&A Agent")
52
+ gr.Markdown("Upload an Excel report and then ask questions about OTB revenue or occupancy.")
53
+
54
+ with gr.Row():
55
+ with gr.Column():
56
+ file_input = gr.File(label="Upload Excel file", type="file")
57
+ upload_output = gr.Textbox(label="Upload status")
58
+
59
+ file_input.upload(upload_excel, file_input, upload_output)
60
+
61
+ gr.ChatInterface(fn=chat_agent, title="Excel Chat Agent")
62
+
63
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas
2
+ openpyxl
3
+ gradio