hlohaus
commited on
Commit
·
272de65
1
Parent(s):
a90f20f
Fix g4f demo space
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
from fastapi import FastAPI, Response, Request
|
| 3 |
from fastapi.responses import RedirectResponse
|
| 4 |
|
| 5 |
-
from g4f.image import images_dir
|
| 6 |
import g4f.api
|
| 7 |
import g4f.Provider
|
| 8 |
|
|
@@ -11,8 +11,8 @@ from demo.BackendApi import BackendApi
|
|
| 11 |
g4f.Provider.__map__["Feature"] = BackendApi
|
| 12 |
|
| 13 |
|
| 14 |
-
g4f.models.demo_models
|
| 15 |
-
from g4f.image import copy_images
|
| 16 |
|
| 17 |
def create_app():
|
| 18 |
g4f.debug.logging = True
|
|
@@ -36,25 +36,25 @@ def create_app():
|
|
| 36 |
api.register_authorization()
|
| 37 |
api.register_validation_exception_handler()
|
| 38 |
|
| 39 |
-
@app.get("/download/{filename}", response_class=RedirectResponse)
|
| 40 |
-
async def download(filename, request: Request):
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
gui_app = g4f.api.WSGIMiddleware(g4f.api.get_gui_app(g4f.api.AppConfig.demo))
|
| 60 |
app.mount("/", gui_app)
|
|
|
|
| 2 |
from fastapi import FastAPI, Response, Request
|
| 3 |
from fastapi.responses import RedirectResponse
|
| 4 |
|
| 5 |
+
#from g4f.image import images_dir
|
| 6 |
import g4f.api
|
| 7 |
import g4f.Provider
|
| 8 |
|
|
|
|
| 11 |
g4f.Provider.__map__["Feature"] = BackendApi
|
| 12 |
|
| 13 |
|
| 14 |
+
#g4f.models.demo_models
|
| 15 |
+
#from g4f.image import copy_images
|
| 16 |
|
| 17 |
def create_app():
|
| 18 |
g4f.debug.logging = True
|
|
|
|
| 36 |
api.register_authorization()
|
| 37 |
api.register_validation_exception_handler()
|
| 38 |
|
| 39 |
+
# @app.get("/download/{filename}", response_class=RedirectResponse)
|
| 40 |
+
# async def download(filename, request: Request):
|
| 41 |
+
# filename = os.path.basename(filename)
|
| 42 |
+
# if "." not in filename:
|
| 43 |
+
# target = os.path.join(images_dir, filename)
|
| 44 |
+
# filename = f"{filename}.jpg"
|
| 45 |
+
# target = os.path.join(images_dir, filename)
|
| 46 |
+
# if not os.path.exists(target):
|
| 47 |
+
# url = str(request.query_params).split("url=", 1)[1]
|
| 48 |
+
# if url:
|
| 49 |
+
# source_url = url.replace("%2F", "/").replace("%3A", ":").replace("%3F", "?")
|
| 50 |
+
# await copy_images(
|
| 51 |
+
# [source_url],
|
| 52 |
+
# target=target,
|
| 53 |
+
# ssl=False,
|
| 54 |
+
# headers=demo.headers if source_url.startswith(BackendApi.url) else None)
|
| 55 |
+
# if not os.path.exists(target):
|
| 56 |
+
# return Response(status_code=404)
|
| 57 |
+
# return RedirectResponse(f"/images/{filename}")
|
| 58 |
|
| 59 |
gui_app = g4f.api.WSGIMiddleware(g4f.api.get_gui_app(g4f.api.AppConfig.demo))
|
| 60 |
app.mount("/", gui_app)
|