Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,46 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def process_text(text):
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Create the Gradio interface
|
| 8 |
iface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
top_secret_key = os.getenv("top_secret")
|
| 5 |
+
|
| 6 |
+
from predibase import Predibase
|
| 7 |
+
|
| 8 |
+
# Pass api_token directly, or get it from the environment variable.
|
| 9 |
+
pb = Predibase(api_token=top_secret_key)
|
| 10 |
+
client = pb.deployments.client("gemma-2-9b")
|
| 11 |
|
| 12 |
def process_text(text):
|
| 13 |
+
text_input = text
|
| 14 |
+
control_prompt = f"""You are an advanced translation model specializing in translating texts from the Ottoman language (old Turkish) to English. Your task is to produce accurate, fluent, and contextually appropriate translations. Maintain the original meaning, tone, and style of the text as much as possible. For religious or culturally significant phrases, try to preserve their essence and convey the intended respect and significance.
|
| 15 |
+
|
| 16 |
+
### Ottoman text:
|
| 17 |
+
{text_input}
|
| 18 |
+
|
| 19 |
+
### English text:
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
max_retries = 1
|
| 23 |
+
for attempt in range(max_retries):
|
| 24 |
+
try:
|
| 25 |
+
# Assuming `client` is your pre-defined translation model client
|
| 26 |
+
result = client.generate(
|
| 27 |
+
control_prompt,
|
| 28 |
+
adapter_id="gemma-2-9b/1",
|
| 29 |
+
max_new_tokens=512,
|
| 30 |
+
temperature=0.7,
|
| 31 |
+
top_p=0.95,
|
| 32 |
+
top_k=50
|
| 33 |
+
).generated_text
|
| 34 |
+
|
| 35 |
+
return f"{result}"
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"Attempt {attempt + 1} failed with error: {e}")
|
| 38 |
+
if attempt < max_retries - 1:
|
| 39 |
+
# Wait before retrying
|
| 40 |
+
time.sleep(1)
|
| 41 |
+
else:
|
| 42 |
+
# If max retries are exhausted, return a failure message
|
| 43 |
+
return "Maalesef şuanda sunucu meşgul, lütfen biraz sonra bir daha deneyin!"
|
| 44 |
|
| 45 |
# Create the Gradio interface
|
| 46 |
iface = gr.Interface(
|