jake2004 commited on
Commit
183b9c5
Β·
verified Β·
1 Parent(s): a8fe9ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -15
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import openpyxl
4
- import xlrd
5
  import docx
6
  from io import BytesIO
7
  from reportlab.pdfgen import canvas
@@ -43,15 +42,15 @@ if API_KEY:
43
  return pd.ExcelFile(file)
44
 
45
  # Function to edit Excel with full tools
46
- def edit_excel(df):
47
- st.write("### Excel Editor with Full Editing Tools")
48
-
49
  # Editable DataFrame
50
  edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True)
51
 
52
  # Apply Formatting Options
53
- col_to_format = st.selectbox("Select Column to Format:", df.columns)
54
- if st.button("Apply Bold Format"):
55
  edited_df[col_to_format] = edited_df[col_to_format].apply(lambda x: f"**{x}**")
56
 
57
  return edited_df
@@ -68,37 +67,39 @@ if API_KEY:
68
  c.save()
69
  return output
70
 
71
- # **πŸ“‚ AI-Powered File Manager UI**
72
- st.title("πŸ“‚ AI-Powered File Manager with NLP & Excel Editor")
73
  st.write("Upload, edit, and manage `.docx`, `.xls` files with AI-powered NLP and full Excel tools.")
74
 
75
  # πŸ“€ File Uploaders
76
- uploaded_files = st.file_uploader("πŸ“„ Upload `.docx` or `.xlsx` Files", type=["docx", "xls", "xlsx"], accept_multiple_files=True)
 
 
77
 
78
  # ✏️ File Editors
79
  edited_docs = {}
80
  edited_excels = {}
81
 
82
- for file in uploaded_files:
83
  if file:
84
- st.subheader(f"πŸ“ Editing File: {file.name}")
85
 
86
  if file.name.endswith(".docx"):
87
  text = load_docx(file)
88
  edited_text = st.text_area(f"Edit {file.name}:", text, height=300)
89
 
90
  # AI Text Suggestion
91
- if st.button(f"✨ Generate AI Suggestion for {file.name}"):
92
  suggestion = generate_suggestion(edited_text)
93
  st.text_area("πŸ€– AI Suggestion:", suggestion, height=200)
94
 
95
  edited_docs[file.name] = edited_text
96
 
97
- elif file.name.endswith(".xls") or file.name.endswith(".xlsx"):
98
  xls = load_excel(file)
99
- sheet_name = st.selectbox(f"πŸ“Š Select Sheet in {file.name}:", xls.sheet_names)
100
  df = pd.read_excel(xls, sheet_name=sheet_name)
101
- edited_df = edit_excel(df)
102
  edited_excels[file.name] = edited_df
103
 
104
  # πŸ“₯ Download Buttons
@@ -130,3 +131,23 @@ if API_KEY:
130
  file_name=file_name,
131
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
132
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
  import openpyxl
 
4
  import docx
5
  from io import BytesIO
6
  from reportlab.pdfgen import canvas
 
42
  return pd.ExcelFile(file)
43
 
44
  # Function to edit Excel with full tools
45
+ def edit_excel(df, file_key):
46
+ st.write(f"### Editing Excel: {file_key}")
47
+
48
  # Editable DataFrame
49
  edited_df = st.data_editor(df, num_rows="dynamic", use_container_width=True)
50
 
51
  # Apply Formatting Options
52
+ col_to_format = st.selectbox(f"Select Column to Format in {file_key}:", df.columns, key=f"col_{file_key}")
53
+ if st.button(f"Apply Bold Format - {file_key}", key=f"btn_{file_key}"):
54
  edited_df[col_to_format] = edited_df[col_to_format].apply(lambda x: f"**{x}**")
55
 
56
  return edited_df
 
67
  c.save()
68
  return output
69
 
70
+ # 🏠 Streamlit UI
71
+ st.title("πŸ“‚ RAG + TinyLlama NLP File Manager")
72
  st.write("Upload, edit, and manage `.docx`, `.xls` files with AI-powered NLP and full Excel tools.")
73
 
74
  # πŸ“€ File Uploaders
75
+ uploaded_files = {}
76
+ for i in range(1, 5):
77
+ uploaded_files[f"File {i}"] = st.file_uploader(f"πŸ“„ Upload File {i}", type=["docx", "xls"])
78
 
79
  # ✏️ File Editors
80
  edited_docs = {}
81
  edited_excels = {}
82
 
83
+ for file_key, file in uploaded_files.items():
84
  if file:
85
+ st.subheader(f"πŸ“ Editing {file_key}: {file.name}")
86
 
87
  if file.name.endswith(".docx"):
88
  text = load_docx(file)
89
  edited_text = st.text_area(f"Edit {file.name}:", text, height=300)
90
 
91
  # AI Text Suggestion
92
+ if st.button(f"✨ Generate AI Suggestion for {file.name}", key=f"suggest_{file_key}"):
93
  suggestion = generate_suggestion(edited_text)
94
  st.text_area("πŸ€– AI Suggestion:", suggestion, height=200)
95
 
96
  edited_docs[file.name] = edited_text
97
 
98
+ elif file.name.endswith(".xls"):
99
  xls = load_excel(file)
100
+ sheet_name = st.selectbox(f"πŸ“Š Select Sheet in {file.name}:", xls.sheet_names, key=f"sheet_{file_key}")
101
  df = pd.read_excel(xls, sheet_name=sheet_name)
102
+ edited_df = edit_excel(df, file_key)
103
  edited_excels[file.name] = edited_df
104
 
105
  # πŸ“₯ Download Buttons
 
131
  file_name=file_name,
132
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
133
  )
134
+
135
+ # πŸ—¨οΈ Chat with TinyLlama about Timetable Conflicts
136
+ st.subheader("πŸ—“οΈ Timetable Conflict Checker")
137
+ query = st.text_input("Ask about conflicts in the uploaded Timetables:")
138
+
139
+ if query:
140
+ conflict_info = "No conflicts detected." # Default response
141
+ for file_key, file in uploaded_files.items():
142
+ if file and file.name.endswith(".xls"):
143
+ xls = load_excel(file)
144
+ for sheet in xls.sheet_names:
145
+ df = pd.read_excel(xls, sheet_name=sheet)
146
+ if "Monday" in df.columns: # Adjust this based on column headers
147
+ monday_data = df["Monday"].dropna().astype(str).tolist()
148
+ response = generate_suggestion(f"Analyze this schedule: {monday_data}. Find conflicts.")
149
+ if "conflict" in response.lower():
150
+ conflict_info = response
151
+
152
+ st.write("πŸ“’ **Conflict Analysis:**")
153
+ st.write(conflict_info)