Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,22 +22,42 @@ import json
|
|
| 22 |
import shutil
|
| 23 |
import os
|
| 24 |
from fastapi import FastAPI, File, UploadFile
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
app = FastAPI()
|
| 27 |
|
| 28 |
@app.get("/")
|
| 29 |
def read_root():
|
| 30 |
app.state.vector_index = None
|
|
|
|
| 31 |
return {"message": "Connected"}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@tool
|
| 34 |
def retrieve(query_text):
|
| 35 |
"""
|
| 36 |
Retrieves relevant information from a vector index based on a query.
|
| 37 |
-
|
| 38 |
Parameters:
|
| 39 |
- query_text (str): Query to search for relevant information.
|
| 40 |
-
|
| 41 |
Returns:
|
| 42 |
- str: Retrieved text from the document.
|
| 43 |
"""
|
|
@@ -84,7 +104,6 @@ async def upload_file(file: UploadFile = File(...)):
|
|
| 84 |
return {"message": message, "filename": file.filename}
|
| 85 |
|
| 86 |
|
| 87 |
-
|
| 88 |
class QueryRequest(BaseModel):
|
| 89 |
message: str
|
| 90 |
|
|
|
|
| 22 |
import shutil
|
| 23 |
import os
|
| 24 |
from fastapi import FastAPI, File, UploadFile
|
| 25 |
+
import time
|
| 26 |
+
import requests
|
| 27 |
+
from datetime import datetime
|
| 28 |
+
|
| 29 |
|
| 30 |
app = FastAPI()
|
| 31 |
|
| 32 |
@app.get("/")
|
| 33 |
def read_root():
|
| 34 |
app.state.vector_index = None
|
| 35 |
+
keep_alive()
|
| 36 |
return {"message": "Connected"}
|
| 37 |
|
| 38 |
+
def keep_alive(space_url="https://1mr-apigmail.hf.space/ping", interval_hours=5):
|
| 39 |
+
while True:
|
| 40 |
+
try:
|
| 41 |
+
print(f"🔄 Pinging {space_url} at {datetime.now()}")
|
| 42 |
+
response = requests.get(space_url)
|
| 43 |
+
|
| 44 |
+
if response.status_code == 200:
|
| 45 |
+
print("")
|
| 46 |
+
else:
|
| 47 |
+
print("")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
print("")
|
| 50 |
+
|
| 51 |
+
time.sleep(interval_hours * 3600)
|
| 52 |
+
|
| 53 |
+
# keep_alive()
|
| 54 |
+
|
| 55 |
@tool
|
| 56 |
def retrieve(query_text):
|
| 57 |
"""
|
| 58 |
Retrieves relevant information from a vector index based on a query.
|
|
|
|
| 59 |
Parameters:
|
| 60 |
- query_text (str): Query to search for relevant information.
|
|
|
|
| 61 |
Returns:
|
| 62 |
- str: Retrieved text from the document.
|
| 63 |
"""
|
|
|
|
| 104 |
return {"message": message, "filename": file.filename}
|
| 105 |
|
| 106 |
|
|
|
|
| 107 |
class QueryRequest(BaseModel):
|
| 108 |
message: str
|
| 109 |
|