eaysu commited on
Commit
7d06f8f
Β·
1 Parent(s): eab8874

secondary commit

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -57,7 +57,7 @@ def translate_text(model_name, text):
57
  except Exception as e:
58
  return f"Error: {str(e)}"
59
 
60
- # Model options
61
  model_options = [
62
  ("English to Turkish", "Helsinki-NLP/opus-mt-tc-big-en-tr"),
63
  ("Turkish to English", "Helsinki-NLP/opus-mt-tc-big-tr-en"),
@@ -77,14 +77,16 @@ model_options = [
77
  ("Chinese to English", "Helsinki-NLP/opus-mt-zh-en")
78
  ]
79
 
80
- # Create Gradio interface
 
 
81
  with gr.Blocks() as demo:
82
  gr.Markdown("# 🌍 Real-Time Sentence Translation")
83
 
84
  with gr.Row():
85
  model_dropdown = gr.Dropdown(
86
  label="Select Translation Model",
87
- choices=[option[0] for option in model_options],
88
  type="value",
89
  )
90
 
@@ -104,8 +106,12 @@ with gr.Blocks() as demo:
104
  def clear_inputs():
105
  return "", ""
106
 
 
 
 
 
107
  translate_button.click(
108
- fn=translate_text,
109
  inputs=[model_dropdown, input_text],
110
  outputs=output_text,
111
  )
 
57
  except Exception as e:
58
  return f"Error: {str(e)}"
59
 
60
+ # Model options (display name, model name)
61
  model_options = [
62
  ("English to Turkish", "Helsinki-NLP/opus-mt-tc-big-en-tr"),
63
  ("Turkish to English", "Helsinki-NLP/opus-mt-tc-big-tr-en"),
 
77
  ("Chinese to English", "Helsinki-NLP/opus-mt-zh-en")
78
  ]
79
 
80
+ # Create mapping for display names to model names
81
+ model_mapping = {name: model for name, model in model_options}
82
+
83
  with gr.Blocks() as demo:
84
  gr.Markdown("# 🌍 Real-Time Sentence Translation")
85
 
86
  with gr.Row():
87
  model_dropdown = gr.Dropdown(
88
  label="Select Translation Model",
89
+ choices=[name for name, _ in model_options], # Show only names
90
  type="value",
91
  )
92
 
 
106
  def clear_inputs():
107
  return "", ""
108
 
109
+ def translate_with_mapping(selected_name, text):
110
+ model_name = model_mapping.get(selected_name, "")
111
+ return translate_text(model_name, text)
112
+
113
  translate_button.click(
114
+ fn=translate_with_mapping,
115
  inputs=[model_dropdown, input_text],
116
  outputs=output_text,
117
  )