Spaces:
Sleeping
Sleeping
syedMohib44
commited on
Commit
Β·
81f4dce
1
Parent(s):
e90608d
Add LFS
Browse files
app.py
CHANGED
|
@@ -259,16 +259,20 @@ def gradio_upload(file):
|
|
| 259 |
return "No file selected."
|
| 260 |
|
| 261 |
try:
|
| 262 |
-
content = str(file) # Works for NamedString
|
| 263 |
import requests
|
| 264 |
|
| 265 |
base_url = os.getenv("HF_SPACE_URL", "http://localhost:7860")
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
if response.status_code == 200:
|
| 269 |
return "β
Data successfully uploaded and indexed!"
|
| 270 |
else:
|
| 271 |
return f"β Failed: {response.text}"
|
|
|
|
| 272 |
except Exception as e:
|
| 273 |
return f"β Error: {str(e)}"
|
| 274 |
|
|
|
|
| 259 |
return "No file selected."
|
| 260 |
|
| 261 |
try:
|
|
|
|
| 262 |
import requests
|
| 263 |
|
| 264 |
base_url = os.getenv("HF_SPACE_URL", "http://localhost:7860")
|
| 265 |
+
|
| 266 |
+
# Open the file as binary
|
| 267 |
+
with open(file.name, "rb") as f:
|
| 268 |
+
files = {"file": (file.name, f, file.type)}
|
| 269 |
+
response = requests.post(f"{base_url}/upload/", files=files)
|
| 270 |
|
| 271 |
if response.status_code == 200:
|
| 272 |
return "β
Data successfully uploaded and indexed!"
|
| 273 |
else:
|
| 274 |
return f"β Failed: {response.text}"
|
| 275 |
+
|
| 276 |
except Exception as e:
|
| 277 |
return f"β Error: {str(e)}"
|
| 278 |
|