HY-MT1.5-1.8B / app.py
playmak3r's picture
Add a temperature slider control in the advanced options and adjust the default temperature value for the translation function
eda9118
raw
history blame
2.18 kB
import gradio as gr
from model import run
from languages import language_names
example_text = "Now let's make my mum's favourite. So three mars bars into the pan. Then we add the tuna and just stir for a bit, just let the chocolate and fish infuse. A sprinkle of olive oil and some tomato ketchup. Now smell that. Oh boy this is going to be incredible."
css = """
body {
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
}
.gradio-container {
font-family: 'Inter', sans-serif;
}
textarea {
border-radius: 12px !important;
font-size: 16px !important;
}
button {
border-radius: 999px !important;
font-weight: 600 !important;
}
"""
with gr.Blocks(
theme=gr.themes.Soft(
primary_hue="indigo",
secondary_hue="cyan",
neutral_hue="slate"
),
css=css
) as app:
gr.Markdown(
"""
# 🌍 Universal Translator
Translate texts quickly between multiple languages.
Simple and functional.
"""
)
with gr.Row():
with gr.Column(scale=1):
source_language = gr.Dropdown(
choices=language_names,
value="English",
label="Source Language"
)
input_text = gr.Textbox(
label="Original text",
placeholder="Please enter the text...",
lines=8,
value=example_text
)
with gr.Column(scale=1):
target_language = gr.Dropdown(
choices=language_names,
value="Portuguese",
label="Target Language"
)
output_text = gr.Textbox(
label="Translation",
lines=8,
interactive=False
)
with gr.Accordion("Advanced Options", open=False):
temp = gr.Slider(0.00, 1.0, step=.05, label="Temperature", value=0.3)
translate_btn = gr.Button("Translate ✨")
translate_btn.click(
run,
inputs=[input_text, target_language, temp],
outputs=output_text
)
if __name__ == "__main__":
app.queue(max_size=10).launch(mcp_server=True)