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()