Spaces:
Sleeping
Sleeping
File size: 2,094 Bytes
ce77544 e5ad44c ce77544 95c7396 f965943 95c7396 7e44fbb 95c7396 7e44fbb 705c6d7 ce77544 705c6d7 884d850 461c516 6599687 ce77544 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import gradio as gr
import os
top_secret_key = os.getenv("top_secret")
from predibase import Predibase
# Pass api_token directly, or get it from the environment variable.
pb = Predibase(api_token=top_secret_key)
client = pb.deployments.client("gemma-2-9b")
def process_text(text,temperature):
print("temparetaure is ", temperature)
text_input = text
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.
### Ottoman text:
{text_input}
### English text:
"""
for i in range(2):
try:
# Assuming `client` is your pre-defined translation model client
result = client.generate(
control_prompt,
adapter_id="gemma-2-9b/1",
max_new_tokens=256,
temperature=0.7,
top_p=0.95,
top_k=50
).generated_text
print("r:", result)
result = result.split("###")[0]
# Stripping any leading/trailing whitespace
result = result.strip()
return f"{result}"
except Exception as e:
return "Maalesef şuanda sunucu meşgul, lütfen biraz sonra bir daha deneyin!"
# Create the Gradio interface
iface = gr.Interface(
fn=process_text, # Function to process input
inputs=[
gr.Textbox(label="Lütfen çevirilecek Türkçe metni girin"), # Type of input widget,
gr.Slider(minimum=0, maximum=1, step=0.01, value=0.7, label="Sıcaklık(Modelin davranışını değiştirir, ya 0.7 ya 1 genelde iyi)")
],
outputs=gr.Textbox(label="İngilizce çeviri"), # Type of output widget,
)
# Launch the app
iface.launch()
|