Spaces:
Sleeping
Sleeping
import streamlit as st | |
import requests | |
import os | |
def find_file(filename, directory): | |
for root, dirs, files in os.walk(directory): | |
if filename in files: | |
return os.path.join(root, filename) | |
return None | |
def main(): | |
st.title('Download File from OneDrive') | |
search_filename = "english_vocab.pkl" | |
download_link = "https://upesstd-my.sharepoint.com/:u:/g/personal/500082340_stu_upes_ac_in/EYwRTq9dcTJHppgydRR-8BMBYY2BehA6jxri5rKehcSZig?e=fjAYDf" | |
save_filename = "classifer.joblib" | |
found_path = find_file(search_filename, os.getcwd()) | |
if found_path: | |
st.success(f"Found {search_filename} at {found_path}") | |
if st.button('Download File'): | |
response = requests.get(download_link, allow_redirects=True) | |
if response.status_code == 200: | |
save_path = os.path.join(os.path.dirname(found_path), save_filename) | |
with open(save_path, 'wb') as file: | |
file.write(response.content) | |
st.success(f"File downloaded successfully and saved as {save_path}") | |
else: | |
st.error(f"Failed to download the file. Status code: {response.status_code}") | |
else: | |
st.error(f"File {search_filename} not found in the current directory or subdirectories.") | |
if __name__ == '__main__': | |
main() | |