Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,19 @@ import random
|
|
| 4 |
import spaces
|
| 5 |
import torch
|
| 6 |
import time
|
|
|
|
| 7 |
from diffusers import DiffusionPipeline, AutoencoderTiny
|
| 8 |
from custom_pipeline import FluxWithCFGPipeline
|
| 9 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# --- Torch Optimizations ---
|
| 12 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
@@ -35,17 +45,19 @@ print("✅ Flux pipeline loaded.")
|
|
| 35 |
|
| 36 |
@spaces.GPU
|
| 37 |
def translate_albanian_to_english(text):
|
| 38 |
-
"""Translate Albanian text to English using
|
| 39 |
if not text.strip():
|
| 40 |
return ""
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
return f"Përkthimi dështoi. Ju lutem provoni përsëri ose përdorni anglisht."
|
| 50 |
|
| 51 |
@spaces.GPU
|
|
|
|
| 4 |
import spaces
|
| 5 |
import torch
|
| 6 |
import time
|
| 7 |
+
import threading
|
| 8 |
from diffusers import DiffusionPipeline, AutoencoderTiny
|
| 9 |
from custom_pipeline import FluxWithCFGPipeline
|
| 10 |
+
from libretranslate import LibreTranslate
|
| 11 |
+
|
| 12 |
+
# --- Start LibreTranslate Server ---
|
| 13 |
+
def start_libretranslate():
|
| 14 |
+
from libretranslate import start_server
|
| 15 |
+
start_server(host="localhost", port=5000)
|
| 16 |
+
|
| 17 |
+
threading.Thread(target=start_libretranslate, daemon=True).start()
|
| 18 |
+
time.sleep(2) # Wait for server to start
|
| 19 |
+
lt = LibreTranslate(host="localhost", port=5000)
|
| 20 |
|
| 21 |
# --- Torch Optimizations ---
|
| 22 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
|
|
| 45 |
|
| 46 |
@spaces.GPU
|
| 47 |
def translate_albanian_to_english(text):
|
| 48 |
+
"""Translate Albanian text to English using local LibreTranslate."""
|
| 49 |
if not text.strip():
|
| 50 |
return ""
|
| 51 |
+
for attempt in range(2):
|
| 52 |
+
try:
|
| 53 |
+
translated = lt.translate(text, source="sq", target="en")
|
| 54 |
+
if translated:
|
| 55 |
+
print(f"LibreTranslate response: {translated}") # Debug
|
| 56 |
+
return translated
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"Translation error (attempt {attempt + 1}): {e}")
|
| 59 |
+
if attempt == 1:
|
| 60 |
+
return f"Përkthimi dështoi: {str(e)}. Ju lutem provoni përsëri ose përdorni anglisht."
|
| 61 |
return f"Përkthimi dështoi. Ju lutem provoni përsëri ose përdorni anglisht."
|
| 62 |
|
| 63 |
@spaces.GPU
|