slimshadow commited on
Commit
fc5ba53
·
verified ·
1 Parent(s): 6f040ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -18,25 +18,23 @@ if uploaded_file is not None:
18
  # Send the file to the server using requests
19
  response = requests.put(server_url, data=uploaded_file.read())
20
 
21
- # Check if the file was uploaded successfully
22
  if response.status_code == 200:
23
  try:
24
- # Parse the response JSON to extract the file ID
25
- response_json = response.json()
26
- file_id = response_json.get("id", None)
27
-
28
  if file_id:
29
- # Display success message and file link
30
  st.write("File uploaded successfully!")
31
- file_url = f"https://buzzheavier.com/f/{file_id}"
32
- st.write(f"[View uploaded file]({file_url})")
 
33
  else:
34
- st.write("File uploaded, but no file ID returned.")
35
- st.write(response.text)
36
  except ValueError:
37
- # Handle case where response isn't JSON formatted
38
- st.write("Failed to parse the server response.")
39
- st.write(response.text)
40
  else:
 
41
  st.write("Failed to upload the file.")
42
  st.write(response.text)
 
18
  # Send the file to the server using requests
19
  response = requests.put(server_url, data=uploaded_file.read())
20
 
21
+ # Check the response status code and content
22
  if response.status_code == 200:
23
  try:
24
+ # Parse the JSON response to get the file ID
25
+ response_data = response.json()
26
+ file_id = response_data.get("id")
27
+
28
  if file_id:
 
29
  st.write("File uploaded successfully!")
30
+ # Provide a direct link to the uploaded file
31
+ file_link = f"https://buzzheavier.com/f/{file_id}"
32
+ st.markdown(f"[View your uploaded file here]({file_link})")
33
  else:
34
+ st.write("File uploaded, but could not retrieve file ID.")
 
35
  except ValueError:
36
+ st.write("File uploaded, but received an invalid response.")
 
 
37
  else:
38
+ # Display the error response from the server
39
  st.write("Failed to upload the file.")
40
  st.write(response.text)