YoniFriedman commited on
Commit
5acc038
·
verified ·
1 Parent(s): 25a95ab

Adding Swahili Translation

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -10,6 +10,11 @@ import sys
10
  llm = OpenAI(temperature=0.0, model="gpt-3.5-turbo")
11
  client = OpenAIOG()
12
 
 
 
 
 
 
13
  # Load index
14
  from llama_index.core import VectorStoreIndex
15
  from llama_index.core import StorageContext
@@ -23,6 +28,12 @@ import gradio as gr
23
  def nishauri(question: str, conversation_history: list[str]):
24
 
25
  context = " ".join([item["user"] + " " + item["chatbot"] for item in conversation_history])
 
 
 
 
 
 
26
  response = query_engine.query(question)
27
 
28
  background = ("The person who asked the question is a person living with HIV."
@@ -50,10 +61,15 @@ def nishauri(question: str, conversation_history: list[str]):
50
  {"role": "user", "content": question_final}
51
  ]
52
  )
 
 
 
 
 
53
 
54
  conversation_history.append({"user": question, "chatbot": response.response})
55
 
56
- return completion.choices[0].message.content, conversation_history
57
 
58
  demo = gr.Interface(
59
  title = "Nishauri Chatbot Demo",
 
10
  llm = OpenAI(temperature=0.0, model="gpt-3.5-turbo")
11
  client = OpenAIOG()
12
 
13
+ from langdetect import detect
14
+ from langdetect import DetectorFactory
15
+ DetectorFactory.seed = 0
16
+ from deep_translator import GoogleTranslator
17
+
18
  # Load index
19
  from llama_index.core import VectorStoreIndex
20
  from llama_index.core import StorageContext
 
28
  def nishauri(question: str, conversation_history: list[str]):
29
 
30
  context = " ".join([item["user"] + " " + item["chatbot"] for item in conversation_history])
31
+
32
+ lang_question = detect(question)
33
+
34
+ if lang_question=="sw":
35
+ question = GoogleTranslator(source='sw', target='en').translate(question)
36
+
37
  response = query_engine.query(question)
38
 
39
  background = ("The person who asked the question is a person living with HIV."
 
61
  {"role": "user", "content": question_final}
62
  ]
63
  )
64
+
65
+ reply_to_user = completion.choices[0].message.content
66
+
67
+ if lang_question=="sw":
68
+ reply_to_user = GoogleTranslator(source='auto', target='sw').translate(reply_to_user)
69
 
70
  conversation_history.append({"user": question, "chatbot": response.response})
71
 
72
+ return reply_to_user, conversation_history
73
 
74
  demo = gr.Interface(
75
  title = "Nishauri Chatbot Demo",