import os import gradio as gr from gradio_client import Client MY_HF_TOKEN_KEY = os.environ["MY_HF_TOKEN_KEY"] #iface = gr.load(name="Ghana-NLP/Khaya-chat-bot",hf_token=MY_HF_TOKEN_KEY,src ='spaces') client = Client("Ghana-NLP/Khaya-chat-bot",hf_token=MY_HF_TOKEN_KEY) history = "" # history string def generate(prompt,language): output = client.predict(prompt,language) history = history + "\n" + output return history with gr.Blocks() as demo: title = gr.Markdown( """ # African Language Chatbot (Khaya) 1. SELECT YOUR LANGUAGE 2. TYPE IN SELECTED LANGUAGE!! 3. REFRESH PAGE TO START FRESH CONVERSATION Based on the Khaya AI Translation API, Lesan AI, Google Translate API and the Mixtral model. Lesan is used for Amharic and Tigrinya, Khaya AI is used for Twi, Dagbani, Ewe, Ga, Gurene, Fante, Kikuyu, Kimeru, Luo, Yoruba and Google is used for Hausa, Swahili and Shona. """) language_selector = gr.Dropdown(["Amharic","Twi","Dagbani","Ewe","Ga","Gurene","Fante","Hausa", "Kikuyu", "Kimeru", "Luo","Shona","Swahili","Tigrinya","Yoruba"],value="Twi",label="Choose Language! (default is Twi)", info="Language:") with gr.Row(): output = gr.Text(label="Conversation:") with gr.Row(): prompt = gr.Text(label="Enter Text In Your Local Language:") btn = gr.Button("Chat") btn.click(generate, inputs=[prompt,language_selector], outputs=[output]) if __name__ == "__main__": demo.queue(max_size=20).launch()