Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,16 +38,22 @@ def translate_albanian_to_english(text):
|
|
| 38 |
"""Translate Albanian text to English using LibreTranslate public instance."""
|
| 39 |
if not text.strip():
|
| 40 |
return ""
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
@spaces.GPU
|
| 53 |
def generate_image(prompt: str, seed: int = 42, aspect_ratio: str = "16:9", randomize_seed: bool = False):
|
|
@@ -124,13 +130,18 @@ def create_demo():
|
|
| 124 |
|
| 125 |
with gr.Row():
|
| 126 |
with gr.Column(scale=2):
|
| 127 |
-
output_image = gr.Image(label="Imazhi i Gjeneruar", interactive=False
|
| 128 |
with gr.Column(scale=1):
|
| 129 |
-
prompt_albanian = gr.Textbox(label="Përshkrimi në Shqip", placeholder="Shkruani përshkrimin në shqip këtu
|
| 130 |
-
prompt_english = gr.Textbox(
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
latency = gr.Textbox(label="Koha", interactive=False)
|
| 135 |
|
| 136 |
prompt_albanian.change(
|
|
@@ -149,5 +160,6 @@ def create_demo():
|
|
| 149 |
return app
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
|
|
|
| 152 |
app = create_demo()
|
| 153 |
app.launch(share=True)
|
|
|
|
| 38 |
"""Translate Albanian text to English using LibreTranslate public instance."""
|
| 39 |
if not text.strip():
|
| 40 |
return ""
|
| 41 |
+
for attempt in range(2): # Retry once
|
| 42 |
+
try:
|
| 43 |
+
response = requests.post(
|
| 44 |
+
"https://libretranslate.de/api/translate",
|
| 45 |
+
json={"q": text, "source": "sq", "target": "en"},
|
| 46 |
+
timeout=5 # 5-second timeout
|
| 47 |
+
)
|
| 48 |
+
response.raise_for_status()
|
| 49 |
+
translated = response.json().get("translatedText", "")
|
| 50 |
+
if translated:
|
| 51 |
+
return translated
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"Translation error (attempt {attempt + 1}): {e}")
|
| 54 |
+
if attempt == 1: # Last attempt
|
| 55 |
+
return f"Gabim në përkthim: {str(e)}. Duke përdorur tekstin origjinal: {text}"
|
| 56 |
+
return text # Fallback to original text
|
| 57 |
|
| 58 |
@spaces.GPU
|
| 59 |
def generate_image(prompt: str, seed: int = 42, aspect_ratio: str = "16:9", randomize_seed: bool = False):
|
|
|
|
| 130 |
|
| 131 |
with gr.Row():
|
| 132 |
with gr.Column(scale=2):
|
| 133 |
+
output_image = gr.Image(label="Imazhi i Gjeneruar", interactive=False)
|
| 134 |
with gr.Column(scale=1):
|
| 135 |
+
prompt_albanian = gr.Textbox(label="Përshkrimi në Shqip", placeholder="Shkruani përshkrimin në shqip këtu", lines=3)
|
| 136 |
+
prompt_english = gr.Textbox(
|
| 137 |
+
label="Përshkrimi në Anglisht",
|
| 138 |
+
placeholder="Përkthimi do të shfaqet këtu",
|
| 139 |
+
interactive=False,
|
| 140 |
+
lines=3
|
| 141 |
+
)
|
| 142 |
+
aspect_ratio = gr.Radio(label="Raporti i Imazhit", choices=list(ASPECT_RATIOS.keys()), value="1:1")
|
| 143 |
+
randomize_seed = gr.Checkbox(label="Përdor numër të rastësishëm", value=False)
|
| 144 |
+
generate_btn = gr.Button("Gjenero")
|
| 145 |
latency = gr.Textbox(label="Koha", interactive=False)
|
| 146 |
|
| 147 |
prompt_albanian.change(
|
|
|
|
| 160 |
return app
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|
| 163 |
+
print(f"Gradio version: {gr.__version__}")
|
| 164 |
app = create_demo()
|
| 165 |
app.launch(share=True)
|