Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,21 +15,27 @@ api_key = os.getenv("HF_API_KEY")
|
|
| 15 |
image_api_url = os.getenv("IMAGE_API_URL")
|
| 16 |
headers = {"Authorization": f"Bearer {api_key}"}
|
| 17 |
|
| 18 |
-
# Danh sách màu sắc
|
| 19 |
color_map = {
|
| 20 |
-
"Đỏ": "
|
| 21 |
-
"Cam": "
|
| 22 |
-
"Vàng": "
|
| 23 |
-
"Lục": "
|
| 24 |
-
"Lam": "
|
| 25 |
-
"Chàm": "
|
| 26 |
-
"Tím": "
|
| 27 |
-
"Trắng": "
|
| 28 |
-
"Đen": "
|
| 29 |
-
"Xám": "
|
| 30 |
-
"Cầu vồng": "
|
| 31 |
}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Hàm gọi API Hugging Face để tạo hình ảnh
|
| 34 |
def query(payload):
|
| 35 |
response = requests.post(image_api_url, headers=headers, json=payload)
|
|
@@ -42,17 +48,12 @@ def translate_to_english(text):
|
|
| 42 |
return translate(text, "en", "vi") # Dịch từ tiếng Việt sang tiếng Anh
|
| 43 |
|
| 44 |
# Hàm xử lý tạo hình ảnh với các lựa chọn
|
| 45 |
-
def generate_image(prompt, view, style, hair_color, eye_color, lip_color):
|
| 46 |
# Dịch prompt từ tiếng Việt sang tiếng Anh
|
| 47 |
prompt_en = translate_to_english(prompt)
|
| 48 |
|
| 49 |
-
# Lấy mã màu hex tương ứng từ tên màu đã chọn
|
| 50 |
-
hair_color_hex = color_map.get(hair_color, "#FF0000")
|
| 51 |
-
eye_color_hex = color_map.get(eye_color, "#FF0000")
|
| 52 |
-
lip_color_hex = color_map.get(lip_color, "#FF0000")
|
| 53 |
-
|
| 54 |
# Thêm các yếu tố lựa chọn vào prompt
|
| 55 |
-
prompt_with_choices = f"{prompt_en}, View: {view}, Style: {style}, Hair color: {
|
| 56 |
|
| 57 |
# Thêm yếu tố ngẫu nhiên vào prompt
|
| 58 |
random_factor = random.randint(1, 1000)
|
|
@@ -84,6 +85,10 @@ iface = gr.Interface(
|
|
| 84 |
["Đỏ", "Cam", "Vàng", "Lục", "Lam", "Chàm", "Tím", "Trắng", "Đen", "Xám", "Cầu vồng"],
|
| 85 |
label="Màu môi"
|
| 86 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
],
|
| 88 |
outputs="image",
|
| 89 |
title="Image Generator - Trần Như Tuấn",
|
|
|
|
| 15 |
image_api_url = os.getenv("IMAGE_API_URL")
|
| 16 |
headers = {"Authorization": f"Bearer {api_key}"}
|
| 17 |
|
| 18 |
+
# Danh sách màu sắc
|
| 19 |
color_map = {
|
| 20 |
+
"Đỏ": "red",
|
| 21 |
+
"Cam": "orange",
|
| 22 |
+
"Vàng": "yellow",
|
| 23 |
+
"Lục": "green",
|
| 24 |
+
"Lam": "blue",
|
| 25 |
+
"Chàm": "indigo",
|
| 26 |
+
"Tím": "violet",
|
| 27 |
+
"Trắng": "white",
|
| 28 |
+
"Đen": "black",
|
| 29 |
+
"Xám": "gray",
|
| 30 |
+
"Cầu vồng": "rainbow",
|
| 31 |
}
|
| 32 |
|
| 33 |
+
# Danh sách kiểu tóc
|
| 34 |
+
hair_styles = [
|
| 35 |
+
"Tóc tự nhiên", "Tóc thẳng mượt", "Tóc buộc nửa đầu", "Tóc búi cao", "Tóc bob",
|
| 36 |
+
"Tóc xoăn sóng", "Tóc tết", "Tóc pixie"
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
# Hàm gọi API Hugging Face để tạo hình ảnh
|
| 40 |
def query(payload):
|
| 41 |
response = requests.post(image_api_url, headers=headers, json=payload)
|
|
|
|
| 48 |
return translate(text, "en", "vi") # Dịch từ tiếng Việt sang tiếng Anh
|
| 49 |
|
| 50 |
# Hàm xử lý tạo hình ảnh với các lựa chọn
|
| 51 |
+
def generate_image(prompt, view, style, hair_color, eye_color, lip_color, hair_style):
|
| 52 |
# Dịch prompt từ tiếng Việt sang tiếng Anh
|
| 53 |
prompt_en = translate_to_english(prompt)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Thêm các yếu tố lựa chọn vào prompt
|
| 56 |
+
prompt_with_choices = f"{prompt_en}, View: {view}, Style: {style}, Hair color: {hair_color}, Eye color: {eye_color}, Lip color: {lip_color}, Hair style: {hair_style}"
|
| 57 |
|
| 58 |
# Thêm yếu tố ngẫu nhiên vào prompt
|
| 59 |
random_factor = random.randint(1, 1000)
|
|
|
|
| 85 |
["Đỏ", "Cam", "Vàng", "Lục", "Lam", "Chàm", "Tím", "Trắng", "Đen", "Xám", "Cầu vồng"],
|
| 86 |
label="Màu môi"
|
| 87 |
),
|
| 88 |
+
gr.Dropdown(
|
| 89 |
+
hair_styles,
|
| 90 |
+
label="Kiểu tóc"
|
| 91 |
+
),
|
| 92 |
],
|
| 93 |
outputs="image",
|
| 94 |
title="Image Generator - Trần Như Tuấn",
|