import gradio as gr import requests import json import os LANGUAGES = ['Akan', 'Arabic', ' Assamese', 'Bambara', 'Bengali', 'Catalan', 'English', 'Spanish', ' Basque', 'French', ' Gujarati', 'Hindi', 'Indonesian', 'Igbo', 'Kikuyu', 'Kannada', 'Ganda', 'Lingala', 'Malayalam', 'Marathi', 'Nepali', 'Chichewa', 'Oriya', 'Panjabi', 'Portuguese', 'Kirundi', 'Kinyarwanda', 'Shona', 'Sotho', 'Swahili', 'Tamil', 'Telugu', 'Tswana', 'Tsonga', 'Twi', 'Urdu', 'Viêt Namese', 'Wolof', 'Xhosa', 'Yoruba', 'Chinese', 'Zulu'] API_URL = "https://api-inference.huggingface.co/models/bigscience/mt0-small" def translate(output, text): """Translate text from input language to output language""" instruction = f"""Translatate to {output}: {text}\nTranslation: """ json_ = { "inputs": instruction, "parameters": { "return_full_text": True, "do_sample": False, "max_new_tokens": 250, }, "options": { "use_cache": True, "wait_for_model": True, }, } response = requests.request("POST", API_URL, json=json_) output = response.json()[0]['generated_text'] return output.replace(instruction, '', 1) demo = gr.Blocks() with demo: gr.Markdown("