| import os |
| import random |
| import sys |
| from typing import Sequence, Mapping, Any, Union |
| import torch |
| from PIL import Image |
| from huggingface_hub import hf_hub_download |
| import spaces |
| import subprocess |
| import gradio |
| import gradio_client |
| import gradio as gr |
| import requests |
|
|
| |
| @spaces.GPU |
| def translate_albanian_to_english(text): |
| """Translate from Albanian to English using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "sq", "to_language": "en", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (sq->en): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_albanian(text): |
| """Translate from English to Albanian using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "sq", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->sq): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_spanish(text): |
| """Translate from English to Spanish using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "es", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->es): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_italian(text): |
| """Translate from English to Italian using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "it", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->it): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_german(text): |
| """Translate from English to German using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "de", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->de): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_french(text): |
| """Translate from English to French using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "fr", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->fr): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_danish(text): |
| """Translate from English to Danish using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "da", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->da): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_swedish(text): |
| """Translate from English to Swedish using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "sv", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->sv): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_norwegian(text): |
| """Translate from English to Norwegian using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "no", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->no): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_finnish(text): |
| """Translate from English to Finnish using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "fi", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->fi): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_arabic(text): |
| """Translate from English to Arabic using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "ar", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->ar): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_portuguese(text): |
| """Translate from English to Portuguese using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "pt", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->pt): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_japanese(text): |
| """Translate from English to Japanese using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "ja", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->ja): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| @spaces.GPU |
| def translate_english_to_dutch(text): |
| """Translate from English to Dutch using the sepioo-facebook-translation API.""" |
| if not text.strip(): |
| raise gr.Error("Please enter a description.") |
| for attempt in range(2): |
| try: |
| response = requests.post( |
| "https://hal1993-mdftranslation1234567890abcdef1234567890-fc073a6.hf.space/v1/translate", |
| json={"from_language": "en", "to_language": "nl", "input_text": text}, |
| headers={"accept": "application/json", "Content-Type": "application/json"}, |
| timeout=5 |
| ) |
| response.raise_for_status() |
| translated = response.json().get("translate", "") |
| print(f"Translation response (en->nl): {translated}") |
| return translated |
| except Exception as e: |
| print(f"Translation error (attempt {attempt + 1}): {e}") |
| if attempt == 1: |
| raise gr.Error("Translation failed. Please try again.") |
| raise gr.Error("Translation failed. Please try again.") |
|
|
| |
| import gradio_client.utils as _gc_utils |
|
|
| _orig_js2pt = _gc_utils._json_schema_to_python_type |
| _orig_get_type = _gc_utils.get_type |
|
|
| def _safe_json_schema_to_python_type(schema, defs=None): |
| if isinstance(schema, bool): |
| return "Any" |
| return _orig_js2pt(schema, defs) |
|
|
| def _safe_get_type(schema): |
| if isinstance(schema, bool): |
| return "Any" |
| return _orig_get_type(schema) |
|
|
| _gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type |
| _gc_utils.get_type = _safe_get_type |
|
|
| print("gradio version:", gradio.__version__) |
| print("gradio_client version:", gradio_client.__version__) |
|
|
| |
| hf_hub_download(repo_id="ezioruan/inswapper_128.onnx", filename="inswapper_128.onnx", local_dir="models/insightface") |
| hf_hub_download(repo_id="martintomov/comfy", filename="facerestore_models/GPEN-BFR-512.onnx", local_dir="models/facerestore_models") |
| hf_hub_download(repo_id="darkeril/collection", filename="detection_Resnet50_Final.pth", local_dir="models/facedetection") |
| hf_hub_download(repo_id="gmk123/GFPGAN", filename="parsing_parsenet.pth", local_dir="models/facedetection") |
| hf_hub_download(repo_id="MonsterMMORPG/tools", filename="1k3d68.onnx", local_dir="models/insightface/models/buffalo_l") |
| hf_hub_download(repo_id="MonsterMMORPG/tools", filename="2d106det.onnx", local_dir="models/insightface/models/buffalo_l") |
| hf_hub_download(repo_id="maze/faceX", filename="det_10g.onnx", local_dir="models/insightface/models/buffalo_l") |
| hf_hub_download(repo_id="typhoon01/aux_models", filename="genderage.onnx", local_dir="models/insightface/models/buffalo_l") |
| hf_hub_download(repo_id="maze/faceX", filename="w600k_r50.onnx", local_dir="models/insightface/models/buffalo_l") |
|
|
| |
| def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any: |
| try: |
| return obj[index] |
| except KeyError: |
| return obj["result"][index] |
|
|
| def find_path(name: str, path: str = None) -> str: |
| if path is None: |
| path = os.getcwd() |
| if name in os.listdir(path): |
| path_name = os.path.join(path, name) |
| print(f"{name} found: {path_name}") |
| return path_name |
| parent_directory = os.path.dirname(path) |
| if parent_directory == path: |
| return None |
| return find_path(name, parent_directory) |
|
|
| def add_comfyui_directory_to_sys_path() -> None: |
| comfyui_path = find_path("ComfyUI") |
| if comfyui_path is not None and os.path.isdir(comfyui_path): |
| sys.path.append(comfyui_path) |
| print(f"'{comfyui_path}' added to sys.path") |
|
|
| def add_extra_model_paths() -> None: |
| try: |
| from main import load_extra_path_config |
| except ImportError: |
| print("Could not import load_extra_path_config from main.py. Looking in utils.extra_config instead.") |
| from utils.extra_config import load_extra_path_config |
| extra_model_paths = find_path("extra_model_paths.yaml") |
| if extra_model_paths is not None: |
| load_extra_path_config(extra_model_paths) |
| else: |
| print("Could not find the extra_model_paths config file.") |
|
|
| add_comfyui_directory_to_sys_path() |
| add_extra_model_paths() |
|
|
| def import_custom_nodes() -> None: |
| import asyncio |
| import execution |
| from nodes import init_extra_nodes |
| import server |
| loop = asyncio.new_event_loop() |
| asyncio.set_event_loop(loop) |
| server_instance = server.PromptServer(loop) |
| execution.PromptQueue(server_instance) |
| init_extra_nodes() |
|
|
| import_custom_nodes() |
| from nodes import NODE_CLASS_MAPPINGS |
|
|
| |
| @spaces.GPU(duration=20) |
| def generate_image(source_image, target_image, target_index): |
| with torch.inference_mode(): |
| loadimage = NODE_CLASS_MAPPINGS["LoadImage"]() |
| loadimage_1 = loadimage.load_image(image=target_image) |
| loadimage_3 = loadimage.load_image(image=source_image) |
| reactorfaceswap = NODE_CLASS_MAPPINGS["ReActorFaceSwap"]() |
| saveimage = NODE_CLASS_MAPPINGS["SaveImage"]() |
| reactorfaceswap_2 = reactorfaceswap.execute( |
| enabled=True, |
| swap_model="inswapper_128.onnx", |
| facedetection="retinaface_resnet50", |
| face_restore_model="GPEN-BFR-512.onnx", |
| face_restore_visibility=1.0, |
| codeformer_weight=0.5, |
| detect_gender_input="no", |
| detect_gender_source="no", |
| input_faces_index=str(target_index), |
| source_faces_index="0", |
| console_log_level=1, |
| input_image=get_value_at_index(loadimage_1, 0), |
| source_image=get_value_at_index(loadimage_3, 0), |
| ) |
| saveimage_4 = saveimage.save_images( |
| filename_prefix="ComfyUI", |
| images=get_value_at_index(reactorfaceswap_2, 0), |
| ) |
| saved_path = f"output/{saveimage_4['ui']['images'][0]['filename']}" |
| return Image.open(saved_path) |
|
|
| |
| def create_demo(): |
| |
| text_elements_en = { |
| "title": "FaceSwap", |
| "subtitle": "Provide source and target image to process faceswapping.", |
| "source_label": "Source Image", |
| "target_label": "Target Image", |
| "index_label": "Target Face Index", |
| "index_desc": "Index_0 = Largest face. To select another, choose Index_1, etc.", |
| "button": "Generate", |
| "output_label": "Generated Image" |
| } |
| |
| |
| text_elements_sq = { |
| key: translate_english_to_albanian(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_es = { |
| key: translate_english_to_spanish(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_it = { |
| key: translate_english_to_italian(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_de = { |
| key: translate_english_to_german(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_fr = { |
| key: translate_english_to_french(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_da = { |
| key: translate_english_to_danish(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_sv = { |
| key: translate_english_to_swedish(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_no = { |
| key: translate_english_to_norwegian(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_fi = { |
| key: translate_english_to_finnish(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_ar = { |
| key: translate_english_to_arabic(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_pt = { |
| key: translate_english_to_portuguese(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_ja = { |
| key: translate_english_to_japanese(value) |
| for key, value in text_elements_en.items() |
| } |
| text_elements_nl = { |
| key: translate_english_to_dutch(value) |
| for key, value in text_elements_en.items() |
| } |
|
|
| with gr.Blocks(css="", title="Face Swap") as app: |
| gr.HTML(""" |
| <style> |
| @import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;700&display=swap'); |
| @keyframes glow { |
| 0% { box-shadow: 0 0 14px rgba(0, 255, 128, 0.5); } |
| 50% { box-shadow: 0 0 14px rgba(0, 255, 128, 0.7); } |
| 100% { box-shadow: 0 0 14px rgba(0, 255, 128, 0.5); } |
| } |
| @keyframes glow-hover { |
| 0% { box-shadow: 0 0 20px rgba(0, 255, 128, 0.7); } |
| 50% { box-shadow: 0 0 20px rgba(0, 255, 128, 0.9); } |
| 100% { box-shadow: 0 0 20px rgba(0, 255, 128, 0.7); } |
| } |
| @keyframes slide { |
| 0% { background-position: 0% 50%; } |
| 50% { background-position: 100% 50%; } |
| 100% { background-position: 0% 50%; } |
| } |
| /* Make tab strip fully transparent */ |
| [role="tablist"], [role="tab"], .gr-tabs-nav, .gr-tabs-nav button, .gr-tabs-nav [role="button"], .gr-tabs-nav .dropdown, .gr-tabs-nav .dropdown * { |
| background: transparent !important; |
| color: transparent !important; |
| border: none !important; |
| opacity: 0 !important; |
| } |
| body { |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| font-family: 'Orbitron', sans-serif; |
| min-height: 100vh; |
| margin: 0 !important; |
| padding: 0 !important; |
| width: 100% !important; |
| max-width: 100vw !important; |
| overflow-x: hidden !important; |
| display: flex !important; |
| justify-content: center; |
| align-items: center; |
| flex-direction: column; |
| } |
| body::before { |
| content: ""; |
| display: block; |
| height: 600px; |
| background: #000000 !important; |
| } |
| .gr-blocks, .container { |
| width: 100% !important; |
| max-width: 100vw !important; |
| margin: 0 !important; |
| padding: 0 !important; |
| box-sizing: border-box !important; |
| overflow-x: hidden !important; |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| } |
| #general_items { |
| width: 100% !important; |
| max-width: 100vw !important; |
| margin: 2rem 0 !important; |
| display: flex !important; |
| flex-direction: column; |
| align-items: center; |
| justify-content: center; |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| } |
| #input_column { |
| background: #000000 !important; |
| border: none !important; |
| border-radius: 8px; |
| padding: 1rem !important; |
| box-shadow: 0 0 10px rgba(255, 255, 255, 0.3) !important; |
| width: 100% !important; |
| max-width: 100vw !important; |
| box-sizing: border-box !important; |
| color: #FFFFFF !important; |
| } |
| h1 { |
| font-size: 5rem; |
| font-weight: 700; |
| text-align: center; |
| color: #FFFFFF !important; |
| text-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important; |
| margin: 0 auto 0.5rem auto; |
| display: block; |
| max-width: 100%; |
| } |
| #subtitle { |
| font-size: 1rem; |
| text-align: center; |
| color: #FFFFFF !important; |
| opacity: 0.8; |
| margin-bottom: 1rem; |
| display: block; |
| max-width: 100%; |
| } |
| .gradio-component { |
| background: #000000 !important; |
| border: none; |
| margin: 0.75rem 0; |
| width: 100% !important; |
| max-width: 100vw !important; |
| color: #FFFFFF !important; |
| } |
| .image-container { |
| aspect-ratio: 1/1; |
| width: 100% !important; |
| max-width: 100vw !important; |
| min-height: 500px; |
| height: auto; |
| border: 0.5px solid #FFFFFF !important; |
| border-radius: 4px; |
| box-sizing: border-box !important; |
| background: #000000 !important; |
| box-shadow: 0 0 10px rgba(255, 255, 255, 0.3) !important; |
| position: relative; |
| color: #FFFFFF !important; |
| } |
| .image-container img { |
| width: 100% !important; |
| height: auto; |
| box-sizing: border-box !important; |
| display: block !important; |
| } |
| .image-container[aria-label="Source Image"] .file-upload, |
| .image-container[aria-label="Source Image"] .file-preview, |
| .image-container[aria-label="Source Image"] .image-actions, |
| .image-container[aria-label="Source Image"] .gr-file-upload, |
| .image-container[aria-label="Source Image"] .gr-file, |
| .image-container[aria-label="Source Image"] .gr-actions, |
| .image-container[aria-label="Source Image"] .gr-upload-button, |
| .image-container[aria-label="Source Image"] .gr-image-toolbar, |
| .image-container[aria-label="Source Image"] .gr-file-actions, |
| .image-container[aria-label="Source Image"] .gr-upload-options, |
| div[aria-label="Source Image"] > div > div:not(.image-container), |
| div[aria-label="Source Image"] .gr-button, |
| .image-container[aria-label="Target Image"] .file-upload, |
| .image-container[aria-label="Target Image"] .file-preview, |
| .image-container[aria-label="Target Image"] .image-actions, |
| .image-container[aria-label="Target Image"] .gr-file-upload, |
| .image-container[aria-label="Target Image"] .gr-file, |
| .image-container[aria-label="Target Image"] .gr-actions, |
| .image-container[aria-label="Target Image"] .gr-upload-button, |
| .image-container[aria-label="Target Image"] .gr-image-toolbar, |
| .image-container[aria-label="Target Image"] .gr-file-actions, |
| .image-container[aria-label="Target Image"] .gr-upload-options, |
| div[aria-label="Target Image"] > div > div:not(.image-container), |
| div[aria-label="Target Image"] .gr-button, |
| .image-container[aria-label="Generated Image"] .file-upload, |
| .image-container[aria-label="Generated Image"] .file-preview, |
| .image-container[aria-label="Generated Image"] .image-actions, |
| .image-container[aria-label="Generated Image"] .gr-file-upload, |
| .image-container[aria-label="Generated Image"] .gr-file, |
| .image-container[aria-label="Generated Image"] .gr-actions, |
| .image-container[aria-label="Generated Image"] .gr-upload-button, |
| .image-container[aria-label="Generated Image"] .gr-image-toolbar, |
| .image-container[aria-label="Generated Image"] .gr-file-actions, |
| .image-container[aria-label="Generated Image"] .gr-upload-options, |
| div[aria-label="Generated Image"] > div > div:not(.image-container), |
| div[aria-label="Generated Image"] .gr-button { |
| display: none !important; |
| } |
| .image-container.processing { |
| background: #000000 !important; |
| } |
| .image-container.processing::before { |
| content: "Processing..."; |
| color: #FFFFFF !important; |
| opacity: 0.7; |
| font-size: 1rem; |
| font-weight: 600; |
| position: absolute; |
| top: 50%; |
| left: 50%; |
| transform: translate(-50%, -50%); |
| text-align: center; |
| width: auto; |
| max-width: 150px; |
| white-space: nowrap; |
| display: inline-block; |
| } |
| input, textarea, .gr-dropdown, .gr-dropdown select { |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| border: 1px solid #FFFFFF !important; |
| border-radius: 4px; |
| padding: 0.5rem; |
| width: 100% !important; |
| max-width: 100vw !important; |
| box-sizing: border-box !important; |
| font-family: 'Orbitron', sans-serif; |
| } |
| input:hover, textarea:hover, .gr-dropdown:hover, .gr-dropdown select:hover { |
| box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important; |
| transition: box-shadow 0.3s; |
| } |
| .gr-button-primary { |
| background: linear-gradient(90deg, rgba(0, 255, 128, 0.3), rgba(0, 200, 100, 0.3), rgba(0, 255, 128, 0.3)) !important; |
| background-size: 200% 100%; |
| animation: slide 4s ease-in-out infinite, glow 3s ease-in-out infinite; |
| color: #FFFFFF !important; |
| border: 1px solid #FFFFFF !important; |
| border-radius: 6px; |
| padding: 0.75rem 1.5rem; |
| font-size: 1.1rem; |
| font-weight: 600; |
| box-shadow: 0 0 14px rgba(0, 255, 128, 0.7) !important; |
| transition: box-shadow 0.3s, transform 0.3s; |
| width: 100% !important; |
| max-width: 100vw !important; |
| min-height: 48px; |
| cursor: pointer; |
| } |
| .gr-button-primary:hover { |
| box-shadow: 0 0 20px rgba(0, 255, 128, 0.9) !important; |
| animation: slide 4s ease-in-out infinite, glow-hover 3s ease-in-out infinite; |
| transform: scale(1.05); |
| } |
| button[aria-label="Fullscreen"], button[aria-label="Fullscreen"]:hover, |
| button[aria-label="Share"], button[aria-label="Share"]:hover { |
| display: none !important; |
| } |
| button[aria-label="Download"] { |
| transform: scale(3); |
| transform-origin: top right; |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| border: 1px solid #FFFFFF !important; |
| border-radius: 4px; |
| padding: 0.4rem !important; |
| margin: 0.5rem !important; |
| box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important; |
| transition: box-shadow 0.3s; |
| } |
| button[aria-label="Download"]:hover { |
| box-shadow: 0 0 12px rgba(255, 255, 255, 0.5) !important; |
| } |
| .progress-text, .gr-progress { |
| display: none !important; |
| } |
| footer, .gr-button-secondary { |
| display: none !important; |
| } |
| .gr-group { |
| background: #000000 !important; |
| border: none !important; |
| width: 100% !important; |
| max-width: 100vw !important; |
| } |
| .gr-tabs { |
| background: #000000 !important; |
| color: #FFFFFF !important; |
| border: none !important; |
| width: 100% !important; |
| max-width: 100vw !important; |
| visibility: hidden; /* Hide content until tab is selected */ |
| } |
| .gr-tabs.tab-loaded { |
| visibility: visible; /* Show content after tab selection */ |
| } |
| /* Hide content of the first tab (Dummy) */ |
| .gr-tabs [role="tabpanel"]:nth-child(1) { |
| display: none !important; |
| } |
| /* Ensure content of other tabs is visible when selected */ |
| .gr-tabs [role="tabpanel"]:nth-child(2), |
| .gr-tabs [role="tabpanel"]:nth-child(3), |
| .gr-tabs [role="tabpanel"]:nth-child(4), |
| .gr-tabs [role="tabpanel"]:nth-child(5), |
| .gr-tabs [role="tabpanel"]:nth-child(6), |
| .gr-tabs [role="tabpanel"]:nth-child(7), |
| .gr-tabs [role="tabpanel"]:nth-child(8), |
| .gr-tabs [role="tabpanel"]:nth-child(9), |
| .gr-tabs [role="tabpanel"]:nth-child(10), |
| .gr-tabs [role="tabpanel"]:nth-child(11), |
| .gr-tabs [role="tabpanel"]:nth-child(12), |
| .gr-tabs [role="tabpanel"]:nth-child(13), |
| .gr-tabs [role="tabpanel"]:nth-child(14), |
| .gr-tabs [role="tabpanel"]:nth-child(15) { |
| display: block !important; |
| } |
| @media (max-width: 768px) { |
| h1 { |
| font-size: 4rem; |
| } |
| #subtitle { |
| font-size: 0.9rem; |
| } |
| .gr-button-primary { |
| padding: 0.6rem 1rem; |
| font-size: 1rem; |
| box-shadow: 0 0 10px rgba(0, 255, 128, 0.7) !important; |
| animation: slide 4s ease-in-out infinite, glow 3s ease-in-out infinite; |
| } |
| .gr-button-primary:hover { |
| box-shadow: 0 0 12px rgba(0, 255, 128, 0.9) !important; |
| animation: slide 4s ease-in-out infinite, glow-hover 3s ease-in-out infinite; |
| } |
| .image-container { |
| min-height: 300px; |
| box-shadow: 0 0 8px rgba(255, 255, 255, 0.3) !important; |
| border: 0.5px solid #FFFFFF !important; |
| } |
| .image-container.processing::before { |
| font-size: 0.9rem; |
| max-width: 90%; |
| white-space: normal; |
| } |
| } |
| </style> |
| <script> |
| document.addEventListener('DOMContentLoaded', () => { |
| console.log('DOM loaded, checking for tabs...'); |
| const urlParams = new URLSearchParams(window.location.search); |
| const tab = urlParams.get('tab')?.toLowerCase(); |
| console.log(`URL tab parameter: ${tab}`); |
| |
| // Initially hide content |
| const tabsContainer = document.querySelector('.gr-tabs'); |
| if (tabsContainer) { |
| tabsContainer.style.visibility = 'hidden'; |
| } |
| |
| // Observe DOM changes to detect when tabs are rendered |
| const observer = new MutationObserver((mutations, obs) => { |
| const tabElements = document.querySelectorAll('[role="tab"], button, div, .gr-tab-item, .tab-item, [data-testid="tab"], [aria-selected]'); |
| console.log(`Found ${tabElements.length} potential tab elements:`, Array.from(tabElements).map(el => ({ text: el.textContent.trim(), class: el.className, role: el.getAttribute('role') }))); |
| |
| if (tabElements.length > 0) { |
| let found = false; |
| tabElements.forEach(el => { |
| const tabText = el.textContent.trim().toLowerCase(); |
| if (tab && (tabText.includes(tab) && (tabText.includes('english') || tabText.includes('albanian') || tabText.includes('spanish') || tabText.includes('italian') || tabText.includes('german') || tabText.includes('french') || tabText.includes('danish') || tabText.includes('swedish') || tabText.includes('norwegian') || tabText.includes('finnish') || tabText.includes('arabic') || tabText.includes('portuguese') || tabText.includes('japanese') || tabText.includes('dutch')))) { |
| console.log(`Found target tab: ${el.textContent.trim()}`); |
| el.click(); |
| el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true })); |
| console.log(`Clicked tab: ${el.textContent.trim()}`); |
| found = true; |
| // Show content after tab selection |
| if (tabsContainer) { |
| tabsContainer.classList.add('tab-loaded'); |
| tabsContainer.style.visibility = 'visible'; |
| } |
| window.scrollTo(0, 0); |
| } |
| }); |
| if (!found) { |
| console.warn(`Tab "${tab}" not found, defaulting to English. Available tabs: ${Array.from(tabElements).map(el => el.textContent.trim()).join(', ')}`); |
| // Default to English (second tab) |
| const englishTab = Array.from(tabElements).find(el => el.textContent.trim().toLowerCase().includes('english')); |
| if (englishTab) { |
| englishTab.click(); |
| englishTab.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true })); |
| console.log('Clicked default English tab'); |
| } |
| if (tabsContainer) { |
| tabsContainer.classList.add('tab-loaded'); |
| tabsContainer.style.visibility = 'visible'; |
| } |
| } |
| // Stop observing once tabs are processed |
| obs.disconnect(); |
| } |
| }); |
| |
| // Start observing the tabs container |
| const tabs = document.querySelector('.gr-tabs, .tabs'); |
| if (tabs) { |
| observer.observe(tabs, { childList: true, subtree: true }); |
| } else { |
| console.warn('Tabs container not found, retrying in 500ms...'); |
| setTimeout(() => { |
| const retryTabs = document.querySelector('.gr-tabs, .tabs'); |
| if (retryTabs) { |
| observer.observe(retryTabs, { childList: true, subtree: true }); |
| } else { |
| console.error('Tabs container still not found, defaulting to English'); |
| if (tabsContainer) { |
| tabsContainer.classList.add('tab-loaded'); |
| tabsContainer.style.visibility = 'visible'; |
| } |
| } |
| }, 500); |
| } |
| |
| // Log and hide toolbar elements |
| const toolbarSelectors = [ |
| '.image-container[aria-label="Source Image"] .file-upload', |
| '.image-container[aria-label="Source Image"] .file-preview', |
| '.image-container[aria-label="Source Image"] .image-actions', |
| '.image-container[aria-label="Source Image"] .gr-file-upload', |
| '.image-container[aria-label="Source Image"] .gr-file', |
| '.image-container[aria-label="Source Image"] .gr-actions', |
| '.image-container[aria-label="Source Image"] .gr-upload-button', |
| '.image-container[aria-label="Source Image"] .gr-image-toolbar', |
| '.image-container[aria-label="Source Image"] .gr-file-actions', |
| '.image-container[aria-label="Source Image"] .gr-upload-options', |
| 'div[aria-label="Source Image"] > div > div:not(.image-container)', |
| 'div[aria-label="Source Image"] .gr-button', |
| '.image-container[aria-label="Target Image"] .file-upload', |
| '.image-container[aria-label="Target Image"] .file-preview', |
| '.image-container[aria-label="Target Image"] .image-actions', |
| '.image-container[aria-label="Target Image"] .gr-file-upload', |
| '.image-container[aria-label="Target Image"] .gr-file', |
| '.image-container[aria-label="Target Image"] .gr-actions', |
| '.image-container[aria-label="Target Image"] .gr-upload-button', |
| '.image-container[aria-label="Target Image"] .gr-image-toolbar', |
| '.image-container[aria-label="Target Image"] .gr-file-actions', |
| '.image-container[aria-label="Target Image"] .gr-upload-options', |
| 'div[aria-label="Target Image"] > div > div:not(.image-container)', |
| 'div[aria-label="Target Image"] .gr-button', |
| '.image-container[aria-label="Generated Image"] .file-upload', |
| '.image-container[aria-label="Generated Image"] .file-preview', |
| '.image-container[aria-label="Generated Image"] .image-actions', |
| '.image-container[aria-label="Generated Image"] .gr-file-upload', |
| '.image-container[aria-label="Generated Image"] .gr-file', |
| '.image-container[aria-label="Generated Image"] .gr-actions', |
| '.image-container[aria-label="Generated Image"] .gr-upload-button', |
| '.image-container[aria-label="Generated Image"] .gr-image-toolbar', |
| '.image-container[aria-label="Generated Image"] .gr-file-actions', |
| '.image-container[aria-label="Generated Image"] .gr-upload-options', |
| 'div[aria-label="Generated Image"] > div > div:not(.image-container)', |
| 'div[aria-label="Generated Image"] .gr-button' |
| ]; |
| toolbarSelectors.forEach(selector => { |
| const elements = document.querySelectorAll(selector); |
| elements.forEach(el => { |
| const style = window.getComputedStyle(el); |
| console.log(`Toolbar element ${selector}: display=${style.display}, class=${el.className}`); |
| }); |
| }); |
| |
| // Force hide any residual toolbar elements |
| const toolbars = document.querySelectorAll( |
| '.image-container[aria-label="Source Image"] > div > div:not(.image-container), ' + |
| '.image-container[aria-label="Source Image"] .file-upload, ' + |
| '.image-container[aria-label="Source Image"] .file-preview, ' + |
| '.image-container[aria-label="Source Image"] .image-actions, ' + |
| '.image-container[aria-label="Source Image"] .gr-file-upload, ' + |
| '.image-container[aria-label="Source Image"] .gr-file, ' + |
| '.image-container[aria-label="Source Image"] .gr-actions, ' + |
| '.image-container[aria-label="Source Image"] .gr-upload-button, ' + |
| '.image-container[aria-label="Source Image"] .gr-image-toolbar, ' + |
| '.image-container[aria-label="Source Image"] .gr-file-actions, ' + |
| '.image-container[aria-label="Source Image"] .gr-upload-options, ' + |
| 'div[aria-label="Source Image"] .gr-button, ' + |
| '.image-container[aria-label="Target Image"] > div > div:not(.image-container), ' + |
| '.image-container[aria-label="Target Image"] .file-upload, ' + |
| '.image-container[aria-label="Target Image"] .file-preview, ' + |
| '.image-container[aria-label="Target Image"] .image-actions, ' + |
| '.image-container[aria-label="Target Image"] .gr-file-upload, ' + |
| '.image-container[aria-label="Target Image"] .gr-file, ' + |
| '.image-container[aria-label="Target Image"] .gr-actions, ' + |
| '.image-container[aria-label="Target Image"] .gr-upload-button, ' + |
| '.image-container[aria-label="Target Image"] .gr-image-toolbar, ' + |
| '.image-container[aria-label="Target Image"] .gr-file-actions, ' + |
| '.image-container[aria-label="Target Image"] .gr-upload-options, ' + |
| 'div[aria-label="Target Image"] .gr-button, ' + |
| '.image-container[aria-label="Generated Image"] > div > div:not(.image-container), ' + |
| '.image-container[aria-label="Generated Image"] .file-upload, ' + |
| '.image-container[aria-label="Generated Image"] .file-preview, ' + |
| '.image-container[aria-label="Generated Image"] .image-actions, ' + |
| '.image-container[aria-label="Generated Image"] .gr-file-upload, ' + |
| '.image-container[aria-label="Generated Image"] .gr-file, ' + |
| '.image-container[aria-label="Generated Image"] .gr-actions, ' + |
| '.image-container[aria-label="Generated Image"] .gr-upload-button, ' + |
| '.image-container[aria-label="Generated Image"] .gr-image-toolbar, ' + |
| '.image-container[aria-label="Generated Image"] .gr-file-actions, ' + |
| '.image-container[aria-label="Generated Image"] .gr-upload-options, ' + |
| 'div[aria-label="Generated Image"] .gr-button' |
| ); |
| toolbars.forEach(toolbar => { |
| toolbar.style.display = 'none'; |
| console.log(`Forced hide toolbar: ${toolbar.className}`); |
| }); |
| |
| // Toggle processing state for each tab's output image |
| const generateButtons = document.querySelectorAll('.gr-button-primary'); |
| const outputImages = document.querySelectorAll('.image-container[aria-label="Generated Image"]'); |
| generateButtons.forEach((button, index) => { |
| const outputImage = outputImages[index]; |
| if (button && outputImage) { |
| button.addEventListener('click', () => { |
| outputImage.classList.add('processing'); |
| console.log(`Processing state added to output_image in tab ${index + 2}`); |
| }); |
| const observer = new MutationObserver(() => { |
| if (outputImage.querySelector('img')) { |
| outputImage.classList.remove('processing'); |
| console.log(`Processing state removed from output_image in tab ${index + 2}`); |
| observer.disconnect(); |
| } |
| }); |
| observer.observe(outputImage, { childList: true, subtree: true }); |
| } |
| }); |
| }); |
| </script> |
| """) |
|
|
| with gr.Tabs(): |
| with gr.TabItem("Dummy"): |
| gr.Markdown("Under construction.") |
| |
|
|
| with gr.TabItem("English"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown("# FaceSwap") |
| gr.Markdown("Provide source and target image to process faceswapping.", elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_en = gr.Image( |
| label="Source Image", |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_en = gr.Image( |
| label="Target Image", |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_en = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label="Target Face Index", |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown("Index_0 = Largest face. To select another, choose Index_1, etc.") |
| generate_btn_en = gr.Button( |
| "Generate", |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_en = gr.Image( |
| label="Generated Image", |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_en.click( |
| fn=generate_image, |
| inputs=[source_image_en, target_image_en, target_index_en], |
| outputs=[output_image_en] |
| ) |
|
|
| with gr.TabItem("Albanian"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_sq['title']}") |
| gr.Markdown(text_elements_sq['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_sq = gr.Image( |
| label=text_elements_sq['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_sq = gr.Image( |
| label=text_elements_sq['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_sq = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_sq['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_sq['index_desc']) |
| generate_btn_sq = gr.Button( |
| text_elements_sq['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_sq = gr.Image( |
| label=text_elements_sq['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_sq.click( |
| fn=generate_image, |
| inputs=[source_image_sq, target_image_sq, target_index_sq], |
| outputs=[output_image_sq] |
| ) |
|
|
| with gr.TabItem("Spanish"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_es['title']}") |
| gr.Markdown(text_elements_es['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_es = gr.Image( |
| label=text_elements_es['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_es = gr.Image( |
| label=text_elements_es['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_es = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_es['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_es['index_desc']) |
| generate_btn_es = gr.Button( |
| text_elements_es['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_es = gr.Image( |
| label=text_elements_es['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_es.click( |
| fn=generate_image, |
| inputs=[source_image_es, target_image_es, target_index_es], |
| outputs=[output_image_es] |
| ) |
|
|
| with gr.TabItem("Italian"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_it['title']}") |
| gr.Markdown(text_elements_it['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_it = gr.Image( |
| label=text_elements_it['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_it = gr.Image( |
| label=text_elements_it['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_it = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_it['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_it['index_desc']) |
| generate_btn_it = gr.Button( |
| text_elements_it['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_it = gr.Image( |
| label=text_elements_it['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_it.click( |
| fn=generate_image, |
| inputs=[source_image_it, target_image_it, target_index_it], |
| outputs=[output_image_it] |
| ) |
|
|
| with gr.TabItem("German"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_de['title']}") |
| gr.Markdown(text_elements_de['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_de = gr.Image( |
| label=text_elements_de['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_de = gr.Image( |
| label=text_elements_de['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_de = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_de['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_de['index_desc']) |
| generate_btn_de = gr.Button( |
| text_elements_de['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_de = gr.Image( |
| label=text_elements_de['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_de.click( |
| fn=generate_image, |
| inputs=[source_image_de, target_image_de, target_index_de], |
| outputs=[output_image_de] |
| ) |
|
|
| with gr.TabItem("French"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_fr['title']}") |
| gr.Markdown(text_elements_fr['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_fr = gr.Image( |
| label=text_elements_fr['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_fr = gr.Image( |
| label=text_elements_fr['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_fr = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_fr['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_fr['index_desc']) |
| generate_btn_fr = gr.Button( |
| text_elements_fr['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_fr = gr.Image( |
| label=text_elements_fr['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_fr.click( |
| fn=generate_image, |
| inputs=[source_image_fr, target_image_fr, target_index_fr], |
| outputs=[output_image_fr] |
| ) |
|
|
| with gr.TabItem("Danish"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_da['title']}") |
| gr.Markdown(text_elements_da['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_da = gr.Image( |
| label=text_elements_da['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_da = gr.Image( |
| label=text_elements_da['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_da = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_da['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_da['index_desc']) |
| generate_btn_da = gr.Button( |
| text_elements_da['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_da = gr.Image( |
| label=text_elements_da['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_da.click( |
| fn=generate_image, |
| inputs=[source_image_da, target_image_da, target_index_da], |
| outputs=[output_image_da] |
| ) |
|
|
| with gr.TabItem("Swedish"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_sv['title']}") |
| gr.Markdown(text_elements_sv['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_sv = gr.Image( |
| label=text_elements_sv['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_sv = gr.Image( |
| label=text_elements_sv['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_sv = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_sv['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_sv['index_desc']) |
| generate_btn_sv = gr.Button( |
| text_elements_sv['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_sv = gr.Image( |
| label=text_elements_sv['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_sv.click( |
| fn=generate_image, |
| inputs=[source_image_sv, target_image_sv, target_index_sv], |
| outputs=[output_image_sv] |
| ) |
|
|
| with gr.TabItem("Norwegian"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_no['title']}") |
| gr.Markdown(text_elements_no['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_no = gr.Image( |
| label=text_elements_no['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_no = gr.Image( |
| label=text_elements_no['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_no = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_no['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_no['index_desc']) |
| generate_btn_no = gr.Button( |
| text_elements_no['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_no = gr.Image( |
| label=text_elements_no['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_no.click( |
| fn=generate_image, |
| inputs=[source_image_no, target_image_no, target_index_no], |
| outputs=[output_image_no] |
| ) |
|
|
| with gr.TabItem("Finnish"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_fi['title']}") |
| gr.Markdown(text_elements_fi['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_fi = gr.Image( |
| label=text_elements_fi['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_fi = gr.Image( |
| label=text_elements_fi['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_fi = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_fi['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_fi['index_desc']) |
| generate_btn_fi = gr.Button( |
| text_elements_fi['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_fi = gr.Image( |
| label=text_elements_fi['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_fi.click( |
| fn=generate_image, |
| inputs=[source_image_fi, target_image_fi, target_index_fi], |
| outputs=[output_image_fi] |
| ) |
|
|
| with gr.TabItem("Arabic"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_ar['title']}") |
| gr.Markdown(text_elements_ar['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_ar = gr.Image( |
| label=text_elements_ar['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_ar = gr.Image( |
| label=text_elements_ar['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_ar = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_ar['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_ar['index_desc']) |
| generate_btn_ar = gr.Button( |
| text_elements_ar['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_ar = gr.Image( |
| label=text_elements_ar['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_ar.click( |
| fn=generate_image, |
| inputs=[source_image_ar, target_image_ar, target_index_ar], |
| outputs=[output_image_ar] |
| ) |
|
|
| with gr.TabItem("Portuguese"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_pt['title']}") |
| gr.Markdown(text_elements_pt['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_pt = gr.Image( |
| label=text_elements_pt['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_pt = gr.Image( |
| label=text_elements_pt['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_pt = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_pt['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_pt['index_desc']) |
| generate_btn_pt = gr.Button( |
| text_elements_pt['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_pt = gr.Image( |
| label=text_elements_pt['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_pt.click( |
| fn=generate_image, |
| inputs=[source_image_pt, target_image_pt, target_index_pt], |
| outputs=[output_image_pt] |
| ) |
|
|
| with gr.TabItem("Japanese"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_ja['title']}") |
| gr.Markdown(text_elements_ja['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_ja = gr.Image( |
| label=text_elements_ja['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_ja = gr.Image( |
| label=text_elements_ja['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_ja = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_ja['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_ja['index_desc']) |
| generate_btn_ja = gr.Button( |
| text_elements_ja['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_ja = gr.Image( |
| label=text_elements_ja['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_ja.click( |
| fn=generate_image, |
| inputs=[source_image_ja, target_image_ja, target_index_ja], |
| outputs=[output_image_ja] |
| ) |
|
|
| with gr.TabItem("Dutch"): |
| with gr.Row(elem_id="general_items"): |
| gr.Markdown(f"# {text_elements_nl['title']}") |
| gr.Markdown(text_elements_nl['subtitle'], elem_id="subtitle") |
| with gr.Column(elem_id="input_column"): |
| source_image_nl = gr.Image( |
| label=text_elements_nl['source_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_image_nl = gr.Image( |
| label=text_elements_nl['target_label'], |
| type="filepath", |
| sources=["upload"], |
| show_download_button=False, |
| show_share_button=False, |
| interactive=True, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| target_index_nl = gr.Dropdown( |
| choices=[0, 1, 2, 3, 4], |
| value=0, |
| label=text_elements_nl['index_label'], |
| elem_classes=["gradio-component", "gr-dropdown"] |
| ) |
| gr.Markdown(text_elements_nl['index_desc']) |
| generate_btn_nl = gr.Button( |
| text_elements_nl['button'], |
| variant="primary", |
| elem_classes=["gradio-component", "gr-button-primary"] |
| ) |
| output_image_nl = gr.Image( |
| label=text_elements_nl['output_label'], |
| show_download_button=True, |
| show_share_button=False, |
| interactive=False, |
| elem_classes=["gradio-component", "image-container"] |
| ) |
| generate_btn_nl.click( |
| fn=generate_image, |
| inputs=[source_image_nl, target_image_nl, target_index_nl], |
| outputs=[output_image_nl] |
| ) |
|
|
| return app |
|
|
| if __name__ == "__main__": |
| print(f"Gradio version: {gr.__version__}") |
| app = create_demo() |
| app.queue().launch(share=True) |