TiberiuCristianLeon commited on
Commit
5b50e0a
·
verified ·
1 Parent(s): c63efca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -437,29 +437,29 @@ def swap_languages(src_lang, tgt_lang):
437
 
438
  def get_info(model_name, sl, tl):
439
  if model_name == "Helsinki-NLP":
440
- return requests.get(f'https://huggingface.co/{model_name}/opus-mt-{sl}-{tl}/raw/main/README.md').text
 
 
 
441
  if model_name == "Argos":
442
  return requests.get(f'https://huggingface.co/TiberiuCristianLeon/Argostranslate/raw/main/README.md').text
443
  if model_name == "Google":
444
- return '### Google Translate'
445
  return requests.get(f'https://huggingface.co/{model_name}/raw/main/README.md').text
446
 
447
  def create_interface():
448
  with gr.Blocks() as interface:
449
  gr.Markdown("### Machine Text Translation with Gradio API and MCP Server")
450
-
451
- # with gr.Row():
452
  input_text = gr.Textbox(label="Enter text to translate:", placeholder="Type your text here, maximum 512 tokens")
453
 
454
- with gr.Row():
455
- s_language = gr.Dropdown(choices=options, value = options[0], label="Source language", interactive=True)
456
- t_language = gr.Dropdown(choices=options, value = options[1], label="Target language", interactive=True)
457
- swap_btn = gr.Button("Swap Languages", size="md")
458
  swap_btn.click(fn=swap_languages, inputs=[s_language, t_language], outputs=[s_language, t_language], api_name=False, show_api=False)
459
 
460
  with gr.Row():
461
  model_name = gr.Dropdown(choices=models, label=f"Select a model. Default is {models[0]}.", value = models[0], interactive=True, scale=3)
462
- # model_infobtn = gr.Button("Model Info", scale=1)
463
  translate_btn = gr.Button("Translate", scale=1)
464
 
465
  translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)
 
437
 
438
  def get_info(model_name, sl, tl):
439
  if model_name == "Helsinki-NLP":
440
+ response = requests.get(f'https://huggingface.co/{model_name}/opus-mt-{sl}-{tl}/raw/main/README.md').text
441
+ if 'Repository not found' in response:
442
+ return '# [Helsinki-NLP](https://huggingface.co/Helsinki-NLP "Helsinki-NLP")'
443
+ return response
444
  if model_name == "Argos":
445
  return requests.get(f'https://huggingface.co/TiberiuCristianLeon/Argostranslate/raw/main/README.md').text
446
  if model_name == "Google":
447
+ return "### Google Translate"
448
  return requests.get(f'https://huggingface.co/{model_name}/raw/main/README.md').text
449
 
450
  def create_interface():
451
  with gr.Blocks() as interface:
452
  gr.Markdown("### Machine Text Translation with Gradio API and MCP Server")
 
 
453
  input_text = gr.Textbox(label="Enter text to translate:", placeholder="Type your text here, maximum 512 tokens")
454
 
455
+ with gr.Row(variant="compact"):
456
+ s_language = gr.Dropdown(choices=options, value = options[0], label="Source language", interactive=True, scale=3)
457
+ t_language = gr.Dropdown(choices=options, value = options[1], label="Target language", interactive=True, scale=3)
458
+ swap_btn = gr.Button("Swap Languages", size="md", scale=1)
459
  swap_btn.click(fn=swap_languages, inputs=[s_language, t_language], outputs=[s_language, t_language], api_name=False, show_api=False)
460
 
461
  with gr.Row():
462
  model_name = gr.Dropdown(choices=models, label=f"Select a model. Default is {models[0]}.", value = models[0], interactive=True, scale=3)
 
463
  translate_btn = gr.Button("Translate", scale=1)
464
 
465
  translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)