File size: 1,727 Bytes
999dd31
da64ad8
f087c51
da64ad8
999dd31
 
f087c51
b2a05bf
f087c51
8893347
 
801ecb8
 
8893347
 
801ecb8
e867a66
f087c51
 
 
8893347
 
 
5080f5b
f087c51
70dc32b
b94f08a
d62c88e
b94f08a
d62c88e
e867a66
8893347
da64ad8
e867a66
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 <a href="https://translation.ghananlp.org/">Khaya AI Translation API</a>, <a href="https://lesan.ai/">Lesan AI</a>, Google Translate API and the Mixtral model. Lesan is used for <b>Amharic</b> and <b>Tigrinya</b>, <a href="https://translation.ghananlp.org/">Khaya AI</a> is used for <b>Twi</b>, <b>Dagbani</b>, <b>Ewe</b>, <b>Ga</b>, <b>Gurene</b>, <b>Fante</b>, <b>Kikuyu</b>, <b>Kimeru</b>, <b>Luo</b>, <b>Yoruba</b> and Google is used for <b>Hausa</b>, <b>Swahili</b> and <b>Shona</b>.
    """)    
    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()