mattn01 commited on
Commit
484fe03
·
verified ·
1 Parent(s): 8da5352

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pyodbc
4
+ import tempfile
5
+ import os
6
+
7
+ # Streamlit page setup
8
+ st.set_page_config(page_title="Excel to SQL Processor", layout="centered")
9
+
10
+ # Title
11
+ st.title("Excel Processor for SQL Database")
12
+
13
+ # Username and Password Input
14
+ st.subheader("Database Credentials")
15
+ username = st.text_input("Database Username", value="", placeholder="Enter your username")
16
+ password = st.text_input("Database Password", value="", type="password", placeholder="Enter your password")
17
+
18
+ # File Upload
19
+ st.subheader("Upload Excel File")
20
+ uploaded_file = st.file_uploader("Choose an Excel file", type=["xlsx"])
21
+
22
+ # Dummy function to simulate processing
23
+ def process_file(username, password, file):
24
+ if not username or not password:
25
+ return "⚠️ Error: Username and password are required!"
26
+
27
+ if file is None:
28
+ return "⚠️ Error: Please upload an Excel file."
29
+
30
+ try:
31
+ # Save the uploaded file temporarily
32
+ temp_dir = tempfile.mkdtemp()
33
+ file_path = os.path.join(temp_dir, file.name)
34
+ with open(file_path, "wb") as f:
35
+ f.write(file.getvalue())
36
+
37
+ # Load the Excel file (dummy processing)
38
+ df = pd.read_excel(file_path)
39
+ result_message = f"✅ File '{file.name}' successfully uploaded and read. {len(df)} rows found."
40
+
41
+ return result_message
42
+
43
+ except Exception as e:
44
+ return f"❌ Error processing file: {str(e)}"
45
+
46
+ # Run Processing Button
47
+ if st.button("Process File"):
48
+ result = process_file(username, password, uploaded_file)
49
+ st.write(result)