Lagyamfi commited on
Commit
d647f33
·
verified ·
1 Parent(s): 3b8c030

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -29
app.py CHANGED
@@ -4,35 +4,39 @@ from gradio_client import Client
4
 
5
  MY_HF_TOKEN_KEY = os.environ["MY_HF_TOKEN_KEY"]
6
 
7
- #iface = gr.load(name="Ghana-NLP/Khaya-chat-bot",hf_token=MY_HF_TOKEN_KEY,src ='spaces')
8
- client = Client("Ghana-NLP/Khaya-chat-backend",hf_token=MY_HF_TOKEN_KEY)
9
 
10
- def generate(prompt,language,history):
11
- history.append("USER: "+prompt+"\n-----\n")
12
- output = client.predict(prompt,language)
13
- history.append("KHAYA: "+output+"\n*****\n")
14
- full_output = ""
15
- for el in history:
16
- full_output = full_output + el
17
- return history,full_output
18
 
19
- with gr.Blocks() as demo:
20
- history_var = gr.State([]) # conversation history
21
- title = gr.Markdown(
22
- """
23
- # African Language Chatbot (Khaya)
24
- 1. SELECT YOUR LANGUAGE
25
- 2. TYPE IN SELECTED LANGUAGE!!
26
- 3. REFRESH PAGE TO START FRESH CONVERSATION \n\n
27
- 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>.
28
- """)
29
- 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:")
30
- with gr.Row():
31
- output = gr.Text(label="OUTPUT WINDOW (Conversation so far):")
32
- with gr.Row():
33
- prompt = gr.Text(label="Enter Text In Your Local Language:")
34
- btn = gr.Button("Chat")
35
- btn.click(generate, inputs=[prompt,language_selector,history_var], outputs=[history_var,output])
36
 
37
- if __name__ == "__main__":
38
- demo.queue(max_size=20).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  MY_HF_TOKEN_KEY = os.environ["MY_HF_TOKEN_KEY"]
6
 
7
+ client = Client("Ghana-NLP/kikuyu-tts",hf_token=MY_HF_TOKEN_KEY)
 
8
 
9
+ def generate(text):
10
+ output = client.predict(text)
11
+ return output
 
 
 
 
 
12
 
13
+ title = "GhanaNLP: Speech Synthesis"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ description = """
16
+ <b>How to use:</b> Enter some Kikuyu text and choose a speaker.
17
+ """
18
+
19
+ examples = [
20
+ ["Nao makĩguthũkĩra indo iria maatahĩte, makĩoya ngʼondu, na ngʼombe, na tũcaũ, magĩcithĩnjĩra hau thĩ, na magĩcirĩanĩria na thakame.", "ki_1"],
21
+ ["Hĩndĩ ĩyo Abimeleku agĩthiĩ kũrĩ Isaaka oimĩte Gerari, marĩ na Ahuzathu ũrĩa wamũtaaraga, na Fikolu mũnene wa ita ciake.", "ki_2"],
22
+ ["Wee nĩũũĩ ũrĩa matu macio macuurĩtio wega, magegania macio ma ũrĩa ũrĩ ũmenyo mũkinyanĩru?", "ki_3"],
23
+ ]
24
+
25
+ gr.Interface(
26
+ fn=synthesize,
27
+ inputs=[
28
+ gr.Text(label="Input Text"),
29
+ gr.Radio(label="Speaker", choices=[
30
+ "ki_1",
31
+ "ki_2",
32
+ "ki_3",
33
+ ],
34
+ value="ki_1"),
35
+ ],
36
+ outputs=[
37
+ gr.Audio(label="Generated Speech", type="numpy"),
38
+ ],
39
+ title=title,
40
+ description=description,
41
+ examples=examples,
42
+ ).launch()