deepak191z commited on
Commit
fff54ab
·
verified ·
1 Parent(s): 9ba6232

Create file_handling.py

Browse files
Files changed (1) hide show
  1. utils/file_handling.py +29 -0
utils/file_handling.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ import streamlit as st
4
+
5
+ def handle_file_upload(uploaded_file, upload_dir):
6
+ input_path = os.path.join(upload_dir, uploaded_file.name)
7
+ with open(input_path, "wb") as f:
8
+ f.write(uploaded_file.read())
9
+
10
+ if " " in uploaded_file.name:
11
+ new_name = uploaded_file.name.replace(" ", "_")
12
+ new_input_path = os.path.join(upload_dir, new_name)
13
+ if new_input_path != input_path:
14
+ os.rename(input_path, new_input_path)
15
+ input_path = new_input_path
16
+
17
+ return input_path
18
+
19
+ def handle_url_download(url_input, upload_dir):
20
+ st.write("Downloading APK from URL...")
21
+ response = requests.get(url_input)
22
+ if response.status_code == 200:
23
+ input_path = os.path.join(upload_dir, os.path.basename(url_input))
24
+ with open(input_path, "wb") as f:
25
+ f.write(response.content)
26
+ return input_path
27
+ else:
28
+ st.error("Failed to download APK from URL. Please check the URL and try again.")
29
+ st.stop()