udt-specs / app.py
slimshadow's picture
Update app.py
7ccb1e7 verified
import streamlit as st
import requests
# Streamlit file uploader interface
st.title("File Uploader")
# Allow all file types by setting type=None
uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
# File details
file_details = {"filename": uploaded_file.name, "filetype": uploaded_file.type}
st.write(file_details)
# Define the server URL and the name under which the file will be stored
server_url = f"https://w.buzzheavier.com/t/{uploaded_file.name}"
# Send the file to the server using requests
response = requests.put(server_url, data=uploaded_file.read())
# Parse the JSON response to get the file ID
try:
response_data = response.json()
file_id = response_data.get("id")
if file_id:
file_link = f"https://buzzheavier.com/f/{file_id}"
if response.status_code == 200:
st.write("File uploaded successfully!")
else:
st.write("File uploaded successfully!")
# Display the link to the file
st.markdown(f"[View your file here]({file_link})")
else:
st.write("Unexpected response format. No file ID found.")
except ValueError:
st.write("Failed to upload the file. Received an invalid response.")