Spaces:
Running
Running
This is first try with encrypted files
Browse files- .gitignore +1 -0
- Dockerfile +21 -0
- requirements.txt +3 -0
- router.py +41 -0
- searcher.py.gpg +0 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
searcher.py
|
Dockerfile
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official Python 3.10.9 image
|
2 |
+
FROM python:3.11.5
|
3 |
+
|
4 |
+
# Copy the current directory contents into the container at .
|
5 |
+
COPY . .
|
6 |
+
|
7 |
+
# Set the working directory to /
|
8 |
+
WORKDIR /
|
9 |
+
|
10 |
+
# Install requirements.txt
|
11 |
+
RUN pip install --no-cache-dir -r /requirements.txt
|
12 |
+
|
13 |
+
# Install GPG
|
14 |
+
RUN apt-get update && apt-get install -y gnupg
|
15 |
+
|
16 |
+
# Decrypt the sensitive file
|
17 |
+
RUN --mount=type=secret,id=DECRYPT_KEY,mode=0444,required=true \
|
18 |
+
gpg --batch --yes --passphrase $(cat /run/secrets/DECRYPT_KEY) --decrypt searcher.py.gpg > searcher.py
|
19 |
+
|
20 |
+
# Start the FastAPI app on port 7860, the default port expected by Spaces
|
21 |
+
CMD ["uvicorn", "router:app", "--host", "0.0.0.0", "--port", "7860"]
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
google-search-results==2.4.2
|
2 |
+
uvicorn==0.29.0
|
3 |
+
fastapi==0.111.0
|
router.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException, Header
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from typing import List
|
4 |
+
from user_SerpAPI import user_Urls
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
user_Agent = user_Urls()
|
8 |
+
|
9 |
+
class Platforms(BaseModel):
|
10 |
+
booking: bool
|
11 |
+
tripadvisor: bool
|
12 |
+
hotels: bool
|
13 |
+
agoda: bool
|
14 |
+
expedia: bool
|
15 |
+
|
16 |
+
|
17 |
+
class UserData(BaseModel):
|
18 |
+
user_Name: str
|
19 |
+
user_ID: int
|
20 |
+
platforms: Platforms
|
21 |
+
|
22 |
+
|
23 |
+
class InputData(BaseModel):
|
24 |
+
data: List[UserData]
|
25 |
+
|
26 |
+
@app.post("/get")
|
27 |
+
async def run_script(input_Data: InputData, token: str = Header(None, alias="api-token")):
|
28 |
+
try:
|
29 |
+
if token:
|
30 |
+
if input_Data.data:
|
31 |
+
res = user_Agent.get_Search_Results(input_Data.data, token)
|
32 |
+
if res:
|
33 |
+
return {"status": 200, "data": res}
|
34 |
+
else:
|
35 |
+
raise HTTPException(status_code=500, detail="The request can not be fulfilled")
|
36 |
+
else:
|
37 |
+
raise HTTPException(status_code=400, detail="the input format is uncorrect")
|
38 |
+
else:
|
39 |
+
raise HTTPException(status_code=400, detail="Missing 'api-token'.")
|
40 |
+
except Exception as e:
|
41 |
+
raise HTTPException(status_code=500, detail=str(e))
|
searcher.py.gpg
ADDED
Binary file (1.72 kB). View file
|
|