Elvis S. commited on
Commit ·
f2f2537
1
Parent(s): b0f5e54
feat: use env var
Browse files- .env.example +2 -0
- .gitignore +2 -1
- __pycache__/hautech.cpython-311.pyc +0 -0
- app.py +16 -7
- hautech.py +6 -3
.env.example
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
LOG=debug
|
| 2 |
+
TOKEN=
|
.gitignore
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
venv
|
| 2 |
.idea
|
| 3 |
.DS_Store
|
| 4 |
-
flagged
|
|
|
|
|
|
| 1 |
venv
|
| 2 |
.idea
|
| 3 |
.DS_Store
|
| 4 |
+
flagged
|
| 5 |
+
.env
|
__pycache__/hautech.cpython-311.pyc
ADDED
|
Binary file (8.95 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import logging
|
|
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
import gradio as gr
|
|
@@ -66,24 +67,32 @@ def inference(file, prompt, quality, seed, version):
|
|
| 66 |
interface = gr.Interface(
|
| 67 |
fn=inference,
|
| 68 |
inputs=[
|
| 69 |
-
gr.File(label="Upload
|
| 70 |
gr.Textbox(label="Enter Prompt", placeholder="Enter your description here"),
|
| 71 |
gr.Dropdown(
|
| 72 |
-
choices=["low", "high"],
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
),
|
|
|
|
| 77 |
gr.Dropdown(
|
| 78 |
choices=["1"], label="Version", value="1", info="Select model version"
|
| 79 |
),
|
| 80 |
],
|
| 81 |
outputs=gr.Gallery(label="Generated Images"),
|
| 82 |
-
title="
|
| 83 |
description="Upload a garment image and provide a prompt to generate related content.",
|
| 84 |
theme="huggingface",
|
| 85 |
)
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
interface.launch()
|
|
|
|
| 1 |
import logging
|
| 2 |
+
import os
|
| 3 |
import random
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
| 67 |
interface = gr.Interface(
|
| 68 |
fn=inference,
|
| 69 |
inputs=[
|
| 70 |
+
gr.File(label="Upload Garment Image"),
|
| 71 |
gr.Textbox(label="Enter Prompt", placeholder="Enter your description here"),
|
| 72 |
gr.Dropdown(
|
| 73 |
+
choices=["low", "high"],
|
| 74 |
+
label="Quality",
|
| 75 |
+
value="low",
|
| 76 |
+
info="Select image quality",
|
| 77 |
),
|
| 78 |
+
gr.Number(label="Seed", value=random.randint(1, 2**64 - 1)),
|
| 79 |
gr.Dropdown(
|
| 80 |
choices=["1"], label="Version", value="1", info="Select model version"
|
| 81 |
),
|
| 82 |
],
|
| 83 |
outputs=gr.Gallery(label="Generated Images"),
|
| 84 |
+
title="Hautech",
|
| 85 |
description="Upload a garment image and provide a prompt to generate related content.",
|
| 86 |
theme="huggingface",
|
| 87 |
)
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
| 90 |
+
log_level = os.getenv("LOG")
|
| 91 |
+
if log_level is not None and log_level.lower() == "debug":
|
| 92 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 93 |
+
|
| 94 |
+
token = os.getenv("TOKEN")
|
| 95 |
+
if not token:
|
| 96 |
+
raise Exception("Token environment variable is required")
|
| 97 |
+
|
| 98 |
interface.launch()
|
hautech.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import logging
|
|
|
|
| 4 |
import random
|
| 5 |
import time
|
| 6 |
-
from os import PathLike
|
| 7 |
import requests
|
| 8 |
from typing import Optional, Dict
|
| 9 |
from pydantic import BaseModel, Field
|
|
@@ -36,7 +36,7 @@ class HautechRequest:
|
|
| 36 |
# todo: use env var
|
| 37 |
def __init__(
|
| 38 |
self,
|
| 39 |
-
token=
|
| 40 |
):
|
| 41 |
self._token: Optional[str] = token
|
| 42 |
self._session = requests.Session()
|
|
@@ -45,6 +45,9 @@ class HautechRequest:
|
|
| 45 |
self._initialize_session_headers()
|
| 46 |
|
| 47 |
def _initialize_session_headers(self):
|
|
|
|
|
|
|
|
|
|
| 48 |
self._session.headers.update(
|
| 49 |
{
|
| 50 |
"Authorization": f"Bearer {self._token}",
|
|
@@ -65,7 +68,7 @@ class HautechRequest:
|
|
| 65 |
|
| 66 |
return response
|
| 67 |
|
| 68 |
-
def upload_image(self, file: PathLike[str] | PathLike[bytes]) -> str:
|
| 69 |
url = f"{self.FILES_URL}/upload/image"
|
| 70 |
response = self._session.request("PUT", url, files={"file": open(file, "rb")})
|
| 71 |
if response.status_code < 200 or response.status_code >= 300:
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import logging
|
| 4 |
+
import os
|
| 5 |
import random
|
| 6 |
import time
|
|
|
|
| 7 |
import requests
|
| 8 |
from typing import Optional, Dict
|
| 9 |
from pydantic import BaseModel, Field
|
|
|
|
| 36 |
# todo: use env var
|
| 37 |
def __init__(
|
| 38 |
self,
|
| 39 |
+
token=os.getenv("TOKEN"),
|
| 40 |
):
|
| 41 |
self._token: Optional[str] = token
|
| 42 |
self._session = requests.Session()
|
|
|
|
| 45 |
self._initialize_session_headers()
|
| 46 |
|
| 47 |
def _initialize_session_headers(self):
|
| 48 |
+
if not self._token:
|
| 49 |
+
raise RuntimeError("TOKEN environment variable is missing")
|
| 50 |
+
|
| 51 |
self._session.headers.update(
|
| 52 |
{
|
| 53 |
"Authorization": f"Bearer {self._token}",
|
|
|
|
| 68 |
|
| 69 |
return response
|
| 70 |
|
| 71 |
+
def upload_image(self, file: os.PathLike[str] | os.PathLike[bytes]) -> str:
|
| 72 |
url = f"{self.FILES_URL}/upload/image"
|
| 73 |
response = self._session.request("PUT", url, files={"file": open(file, "rb")})
|
| 74 |
if response.status_code < 200 or response.status_code >= 300:
|