Spaces:
Sleeping
Sleeping
Another001
commited on
Commit
•
4e46113
1
Parent(s):
dd68c5c
GPT API
Browse files- Dockerfile +11 -0
- main.py +27 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
class Item(BaseModel):
|
7 |
+
content: str
|
8 |
+
|
9 |
+
@app.post("/write_file/")
|
10 |
+
async def write_file(item: Item):
|
11 |
+
try:
|
12 |
+
with open('/tmp/tes.txt', 'w') as f:
|
13 |
+
f.write(item.content)
|
14 |
+
return {"message": "File has been written successfully."}
|
15 |
+
except Exception as e:
|
16 |
+
raise HTTPException(status_code=500, detail=str(e))
|
17 |
+
|
18 |
+
@app.get("/read_file/")
|
19 |
+
async def read_file():
|
20 |
+
try:
|
21 |
+
with open('/tmp/tes.txt', 'r') as f:
|
22 |
+
data = f.read()
|
23 |
+
return {"content": data}
|
24 |
+
except FileNotFoundError:
|
25 |
+
raise HTTPException(status_code=404, detail="File not found")
|
26 |
+
except Exception as e:
|
27 |
+
raise HTTPException(status_code=500, detail=str(e))
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
characterai
|
4 |
+
g4f
|