Upload utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
@st.cache_data
|
| 6 |
+
def upload_file(file, api_key, ai_id):
|
| 7 |
+
file_data = {"file": file}
|
| 8 |
+
url = f'https://mygpt.felo.me/api/v1/ais/{ai_id}/files'
|
| 9 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
| 10 |
+
try:
|
| 11 |
+
response = requests.post(url, headers=headers, files=file_data)
|
| 12 |
+
print("upload")
|
| 13 |
+
return True
|
| 14 |
+
except requests.exceptions.HTTPError as err:
|
| 15 |
+
return False
|