Wajahat698 commited on
Commit
c980fe2
·
verified ·
1 Parent(s): 948f767

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -152,14 +152,26 @@ def merge_markdown_contents(contents):
152
  merged_content = "\n\n---\n\n".join(contents)
153
  return merged_content
154
 
155
- def upload_to_firebase(user_id, content):
 
 
 
156
  try:
 
 
 
 
 
 
157
  # Create a unique filename
158
  filename = f"knowledge_bases/{user_id}/knowledge_base_{uuid.uuid4()}.md"
 
159
  # Upload content to Firebase Storage
160
  storage.child(filename).put(content.encode('utf-8'))
 
161
  # Get the public URL
162
  public_url = storage.child(filename).get_url(None)
 
163
  return public_url
164
  except Exception as e:
165
  st.error(f"Error uploading to Firebase: {e}")
 
152
  merged_content = "\n\n---\n\n".join(contents)
153
  return merged_content
154
 
155
+ def upload_to_firebase(user_id, file):
156
+ """
157
+ Uploads the content of a file to Firebase Storage.
158
+ """
159
  try:
160
+ # Detect file type and convert to Markdown
161
+ content = convert_file_to_md(file)
162
+ if not content:
163
+ st.error("File conversion failed. Unsupported or empty file.")
164
+ return None
165
+
166
  # Create a unique filename
167
  filename = f"knowledge_bases/{user_id}/knowledge_base_{uuid.uuid4()}.md"
168
+
169
  # Upload content to Firebase Storage
170
  storage.child(filename).put(content.encode('utf-8'))
171
+
172
  # Get the public URL
173
  public_url = storage.child(filename).get_url(None)
174
+ st.success(f"File '{file.name}' uploaded successfully!")
175
  return public_url
176
  except Exception as e:
177
  st.error(f"Error uploading to Firebase: {e}")