Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -57,21 +57,18 @@ def translate_albanian_to_english(text):
|
|
| 57 |
return f"Përkthimi dështoi"
|
| 58 |
|
| 59 |
@spaces.GPU
|
| 60 |
-
def generate_image_from_albanian(prompt_albanian: str,
|
| 61 |
"""Translate Albanian prompt to English and generate image."""
|
| 62 |
if not prompt_albanian.strip():
|
| 63 |
-
return None
|
| 64 |
|
| 65 |
# Translate stealthily
|
| 66 |
prompt_english = translate_albanian_to_english(prompt_albanian)
|
| 67 |
if prompt_english.startswith("Përkthimi dështoi"):
|
| 68 |
-
return None
|
| 69 |
|
| 70 |
if pipe is None:
|
| 71 |
-
return None
|
| 72 |
-
|
| 73 |
-
if randomize_seed:
|
| 74 |
-
seed = random.randint(0, MAX_SEED)
|
| 75 |
|
| 76 |
width, height = ASPECT_RATIOS.get(aspect_ratio, (DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 77 |
|
|
@@ -80,8 +77,8 @@ def generate_image_from_albanian(prompt_albanian: str, seed: int = 42, aspect_ra
|
|
| 80 |
print(f"🎯 Prompt for generation: {prompt_final}")
|
| 81 |
|
| 82 |
try:
|
|
|
|
| 83 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 84 |
-
start_time = time.time()
|
| 85 |
with torch.inference_mode():
|
| 86 |
images = pipe(
|
| 87 |
prompt=prompt_final,
|
|
@@ -93,13 +90,11 @@ def generate_image_from_albanian(prompt_albanian: str, seed: int = 42, aspect_ra
|
|
| 93 |
return_dict=False
|
| 94 |
)
|
| 95 |
image = images[0][0]
|
| 96 |
-
|
| 97 |
-
status = f"Koha e përpunimit: {latency:.2f} sekonda"
|
| 98 |
-
return image, seed, status
|
| 99 |
except Exception as e:
|
| 100 |
if torch.cuda.is_available():
|
| 101 |
torch.cuda.empty_cache()
|
| 102 |
-
return None
|
| 103 |
|
| 104 |
# UI Layout
|
| 105 |
def create_demo():
|
|
|
|
| 57 |
return f"Përkthimi dështoi"
|
| 58 |
|
| 59 |
@spaces.GPU
|
| 60 |
+
def generate_image_from_albanian(prompt_albanian: str, aspect_ratio: str = "1:1"):
|
| 61 |
"""Translate Albanian prompt to English and generate image."""
|
| 62 |
if not prompt_albanian.strip():
|
| 63 |
+
return None
|
| 64 |
|
| 65 |
# Translate stealthily
|
| 66 |
prompt_english = translate_albanian_to_english(prompt_albanian)
|
| 67 |
if prompt_english.startswith("Përkthimi dështoi"):
|
| 68 |
+
return None
|
| 69 |
|
| 70 |
if pipe is None:
|
| 71 |
+
return None
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
width, height = ASPECT_RATIOS.get(aspect_ratio, (DEFAULT_WIDTH, DEFAULT_HEIGHT))
|
| 74 |
|
|
|
|
| 77 |
print(f"🎯 Prompt for generation: {prompt_final}")
|
| 78 |
|
| 79 |
try:
|
| 80 |
+
seed = random.randint(0, MAX_SEED)
|
| 81 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
|
|
| 82 |
with torch.inference_mode():
|
| 83 |
images = pipe(
|
| 84 |
prompt=prompt_final,
|
|
|
|
| 90 |
return_dict=False
|
| 91 |
)
|
| 92 |
image = images[0][0]
|
| 93 |
+
return image
|
|
|
|
|
|
|
| 94 |
except Exception as e:
|
| 95 |
if torch.cuda.is_available():
|
| 96 |
torch.cuda.empty_cache()
|
| 97 |
+
return None
|
| 98 |
|
| 99 |
# UI Layout
|
| 100 |
def create_demo():
|