Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
import spaces
|
| 5 |
import torch
|
| 6 |
import time
|
| 7 |
-
import
|
| 8 |
from diffusers import DiffusionPipeline, AutoencoderTiny
|
| 9 |
from custom_pipeline import FluxWithCFGPipeline
|
| 10 |
-
from libretranslatepy import LibreTranslateAPI
|
| 11 |
-
|
| 12 |
-
# Start LibreTranslate Server
|
| 13 |
-
def start_libretranslate():
|
| 14 |
-
from libretranslate.main import start
|
| 15 |
-
start(host="0.0.0.0", port=5000, no_cache=True)
|
| 16 |
-
|
| 17 |
-
threading.Thread(target=start_libretranslate, daemon=True).start()
|
| 18 |
-
time.sleep(5)
|
| 19 |
-
lt = LibreTranslateAPI("http://localhost:5000")
|
| 20 |
|
| 21 |
# Torch Optimizations
|
| 22 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
@@ -43,24 +32,28 @@ pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtyp
|
|
| 43 |
pipe.to(device)
|
| 44 |
print("✅ Flux pipeline loaded.")
|
| 45 |
|
| 46 |
-
@spaces.GPU
|
| 47 |
def translate_albanian_to_english(text):
|
| 48 |
-
"""Translate Albanian to English using
|
| 49 |
if not text.strip():
|
| 50 |
return ""
|
| 51 |
for attempt in range(2):
|
| 52 |
try:
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)}. Provoni përsëri ose përdorni anglisht."
|
| 61 |
return f"Përkthimi dështoi. Provoni përsëri ose përdorni anglisht."
|
| 62 |
|
| 63 |
-
@spaces.GPU
|
| 64 |
def generate_image(prompt: str, seed: int = 42, aspect_ratio: str = "16:9", randomize_seed: bool = False):
|
| 65 |
"""Generate image from English prompt."""
|
| 66 |
if pipe is None:
|
|
@@ -167,4 +160,4 @@ def create_demo():
|
|
| 167 |
if __name__ == "__main__":
|
| 168 |
print(f"Gradio version: {gr.__version__}")
|
| 169 |
app = create_demo()
|
| 170 |
-
app.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
|
|
|
| 4 |
import torch
|
| 5 |
import time
|
| 6 |
+
import requests
|
| 7 |
from diffusers import DiffusionPipeline, AutoencoderTiny
|
| 8 |
from custom_pipeline import FluxWithCFGPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Torch Optimizations
|
| 11 |
torch.backends.cuda.matmul.allow_tf32 = True
|
|
|
|
| 32 |
pipe.to(device)
|
| 33 |
print("✅ Flux pipeline loaded.")
|
| 34 |
|
|
|
|
| 35 |
def translate_albanian_to_english(text):
|
| 36 |
+
"""Translate Albanian to English using sepioo-facebook-translation API."""
|
| 37 |
if not text.strip():
|
| 38 |
return ""
|
| 39 |
for attempt in range(2):
|
| 40 |
try:
|
| 41 |
+
response = requests.post(
|
| 42 |
+
"https://sepioo-facebook-translation.hf.space/translate",
|
| 43 |
+
json={"from_language": "sq", "to_language": "en", "input_text": text},
|
| 44 |
+
headers={"accept": "application/json", "Content-Type": "application/json"},
|
| 45 |
+
timeout=5
|
| 46 |
+
)
|
| 47 |
+
response.raise_for_status()
|
| 48 |
+
translated = response.json().get("translate", "")
|
| 49 |
+
print(f"Translation response: {translated}")
|
| 50 |
+
return translated
|
| 51 |
except Exception as e:
|
| 52 |
print(f"Translation error (attempt {attempt + 1}): {e}")
|
| 53 |
if attempt == 1:
|
| 54 |
return f"Përkthimi dështoi: {str(e)}. Provoni përsëri ose përdorni anglisht."
|
| 55 |
return f"Përkthimi dështoi. Provoni përsëri ose përdorni anglisht."
|
| 56 |
|
|
|
|
| 57 |
def generate_image(prompt: str, seed: int = 42, aspect_ratio: str = "16:9", randomize_seed: bool = False):
|
| 58 |
"""Generate image from English prompt."""
|
| 59 |
if pipe is None:
|
|
|
|
| 160 |
if __name__ == "__main__":
|
| 161 |
print(f"Gradio version: {gr.__version__}")
|
| 162 |
app = create_demo()
|
| 163 |
+
app.launch()
|