Spaces:
Running
Running
Disable access log
Browse files- Dockerfile +1 -1
- app.py +17 -14
- clean.py +5 -0
- demo/__init__.py +1 -0
Dockerfile
CHANGED
|
@@ -12,4 +12,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
| 12 |
|
| 13 |
COPY --chown=user . /app
|
| 14 |
|
| 15 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 12 |
|
| 13 |
COPY --chown=user . /app
|
| 14 |
|
| 15 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--no-access-log"]
|
app.py
CHANGED
|
@@ -23,6 +23,8 @@ from g4f.providers.response import Parameters, FinishReason, Usage, Reasoning
|
|
| 23 |
from g4f.errors import ModelNotSupportedError
|
| 24 |
from g4f import debug
|
| 25 |
|
|
|
|
|
|
|
| 26 |
class BackendApi(AsyncGeneratorProvider, ProviderModelMixin):
|
| 27 |
url = "https://ahe.hopto.org"
|
| 28 |
working = True
|
|
@@ -84,7 +86,7 @@ class BackendApi(AsyncGeneratorProvider, ProviderModelMixin):
|
|
| 84 |
|
| 85 |
async with StreamSession(
|
| 86 |
proxy=proxy,
|
| 87 |
-
headers={"Accept": "text/event-stream"},
|
| 88 |
timeout=timeout
|
| 89 |
) as session:
|
| 90 |
model = cls.get_model(model)
|
|
@@ -215,15 +217,6 @@ def create_app():
|
|
| 215 |
g4f.api.AppConfig.gui = True
|
| 216 |
g4f.api.AppConfig.demo = False
|
| 217 |
|
| 218 |
-
class NoHomeFilter(logging.Filter):
|
| 219 |
-
def filter(self, record):
|
| 220 |
-
if '"GET / HTTP/1.1" 200 OK' in record.getMessage():
|
| 221 |
-
return False
|
| 222 |
-
if '"GET /static/' in record.getMessage():
|
| 223 |
-
return False
|
| 224 |
-
return True
|
| 225 |
-
logging.getLogger("uvicorn.access").addFilter(NoHomeFilter())
|
| 226 |
-
|
| 227 |
app = FastAPI()
|
| 228 |
|
| 229 |
# Add CORS middleware
|
|
@@ -241,11 +234,12 @@ def create_app():
|
|
| 241 |
api.register_authorization()
|
| 242 |
api.register_validation_exception_handler()
|
| 243 |
|
| 244 |
-
headers = {}
|
| 245 |
-
|
| 246 |
@app.get("/download/{filename}", response_class=RedirectResponse)
|
| 247 |
async def download(filename, request: Request):
|
| 248 |
filename = os.path.basename(filename)
|
|
|
|
|
|
|
|
|
|
| 249 |
target = os.path.join(images_dir, filename)
|
| 250 |
if not os.path.exists(target):
|
| 251 |
url = str(request.query_params).split("url=", 1)[1]
|
|
@@ -255,9 +249,8 @@ def create_app():
|
|
| 255 |
[source_url],
|
| 256 |
target=target,
|
| 257 |
ssl=False,
|
| 258 |
-
headers=headers if source_url.startswith(BackendApi.url) else None)
|
| 259 |
if not os.path.exists(target):
|
| 260 |
-
|
| 261 |
return Response(status_code=404)
|
| 262 |
return RedirectResponse(f"/images/{filename}")
|
| 263 |
|
|
@@ -266,4 +259,14 @@ def create_app():
|
|
| 266 |
|
| 267 |
return app
|
| 268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
app = create_app()
|
|
|
|
| 23 |
from g4f.errors import ModelNotSupportedError
|
| 24 |
from g4f import debug
|
| 25 |
|
| 26 |
+
import demo
|
| 27 |
+
|
| 28 |
class BackendApi(AsyncGeneratorProvider, ProviderModelMixin):
|
| 29 |
url = "https://ahe.hopto.org"
|
| 30 |
working = True
|
|
|
|
| 86 |
|
| 87 |
async with StreamSession(
|
| 88 |
proxy=proxy,
|
| 89 |
+
headers={"Accept": "text/event-stream", **demo.headers},
|
| 90 |
timeout=timeout
|
| 91 |
) as session:
|
| 92 |
model = cls.get_model(model)
|
|
|
|
| 217 |
g4f.api.AppConfig.gui = True
|
| 218 |
g4f.api.AppConfig.demo = False
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
app = FastAPI()
|
| 221 |
|
| 222 |
# Add CORS middleware
|
|
|
|
| 234 |
api.register_authorization()
|
| 235 |
api.register_validation_exception_handler()
|
| 236 |
|
|
|
|
|
|
|
| 237 |
@app.get("/download/{filename}", response_class=RedirectResponse)
|
| 238 |
async def download(filename, request: Request):
|
| 239 |
filename = os.path.basename(filename)
|
| 240 |
+
if "." not in filename:
|
| 241 |
+
target = os.path.join(images_dir, filename)
|
| 242 |
+
filename = f"{filename}.jpg"
|
| 243 |
target = os.path.join(images_dir, filename)
|
| 244 |
if not os.path.exists(target):
|
| 245 |
url = str(request.query_params).split("url=", 1)[1]
|
|
|
|
| 249 |
[source_url],
|
| 250 |
target=target,
|
| 251 |
ssl=False,
|
| 252 |
+
headers=demo.headers if source_url.startswith(BackendApi.url) else None)
|
| 253 |
if not os.path.exists(target):
|
|
|
|
| 254 |
return Response(status_code=404)
|
| 255 |
return RedirectResponse(f"/images/{filename}")
|
| 256 |
|
|
|
|
| 259 |
|
| 260 |
return app
|
| 261 |
|
| 262 |
+
|
| 263 |
+
class NoHomeFilter(logging.Filter):
|
| 264 |
+
def filter(self, record):
|
| 265 |
+
if '"GET / HTTP/1.1" 200 OK' in record.getMessage():
|
| 266 |
+
return False
|
| 267 |
+
if '"GET /static/' in record.getMessage():
|
| 268 |
+
return False
|
| 269 |
+
return True
|
| 270 |
+
logging.getLogger("uvicorn.access").addFilter(NoHomeFilter())
|
| 271 |
+
|
| 272 |
app = create_app()
|
clean.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
for root, _, files in os.walk("./generated_images"):
|
| 3 |
+
for file in files:
|
| 4 |
+
if "." not in file:
|
| 5 |
+
os.rename(file, f"./generated_images/{file}.jpg")
|
demo/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
headers = {"Authorization": "Basic Z2dnOmc0Zl8="}
|