Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -1,23 +1,20 @@
|
|
1 |
-
from fastapi import FastAPI, File, UploadFile
|
2 |
-
from fastapi import
|
3 |
-
from fastapi.responses import HTMLResponse, FileResponse
|
4 |
from fastapi.staticfiles import StaticFiles
|
5 |
from fastapi.templating import Jinja2Templates
|
6 |
-
from fastapi import
|
7 |
-
from
|
8 |
-
from fastapi.responses import StreamingResponse
|
9 |
-
from gradio_client import Client
|
10 |
import os
|
11 |
-
import io
|
12 |
import tempfile
|
|
|
|
|
13 |
app = FastAPI()
|
14 |
|
|
|
15 |
hf_token = os.environ.get('HF_TOKEN')
|
16 |
-
client = Client("
|
17 |
-
|
18 |
-
import tempfile
|
19 |
-
from fastapi.middleware.cors import CORSMiddleware
|
20 |
|
|
|
21 |
app.add_middleware(
|
22 |
CORSMiddleware,
|
23 |
allow_origins=["*"], # Adjust as needed, '*' allows requests from any origin
|
@@ -26,13 +23,6 @@ app.add_middleware(
|
|
26 |
allow_headers=["*"],
|
27 |
)
|
28 |
|
29 |
-
|
30 |
-
import base64
|
31 |
-
|
32 |
-
import logging
|
33 |
-
|
34 |
-
logging.basicConfig(level=logging.DEBUG)
|
35 |
-
|
36 |
@app.post("/upload/")
|
37 |
async def upload_file(file: UploadFile = File(...)):
|
38 |
# Save the uploaded file to a temporary location
|
@@ -65,15 +55,3 @@ async def upload_file(file: UploadFile = File(...)):
|
|
65 |
# Clean up the temporary file
|
66 |
if os.path.exists(temp_file_path):
|
67 |
os.unlink(temp_file_path)
|
68 |
-
|
69 |
-
# Serve static files from the "static" directory
|
70 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
71 |
-
|
72 |
-
@app.get("/", response_class=HTMLResponse)
|
73 |
-
def index(request: Request):
|
74 |
-
return FileResponse("static/index.html")
|
75 |
-
|
76 |
-
# Endpoint to serve the result files
|
77 |
-
@app.get("/result/{filename}")
|
78 |
-
async def get_result(filename: str):
|
79 |
-
return FileResponse(filename)
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException, Request
|
2 |
+
from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
|
|
|
3 |
from fastapi.staticfiles import StaticFiles
|
4 |
from fastapi.templating import Jinja2Templates
|
5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
6 |
+
from gradio_client import Client, handle_file
|
|
|
|
|
7 |
import os
|
|
|
8 |
import tempfile
|
9 |
+
import base64
|
10 |
+
|
11 |
app = FastAPI()
|
12 |
|
13 |
+
# Retrieve Hugging Face token from environment variables
|
14 |
hf_token = os.environ.get('HF_TOKEN')
|
15 |
+
client = Client("Ashrafb/image-to-sketch-ari", hf_token=hf_token)
|
|
|
|
|
|
|
16 |
|
17 |
+
# Configure CORS middleware
|
18 |
app.add_middleware(
|
19 |
CORSMiddleware,
|
20 |
allow_origins=["*"], # Adjust as needed, '*' allows requests from any origin
|
|
|
23 |
allow_headers=["*"],
|
24 |
)
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
@app.post("/upload/")
|
27 |
async def upload_file(file: UploadFile = File(...)):
|
28 |
# Save the uploaded file to a temporary location
|
|
|
55 |
# Clean up the temporary file
|
56 |
if os.path.exists(temp_file_path):
|
57 |
os.unlink(temp_file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|