Commit
·
168dd6b
1
Parent(s):
3f9d5b2
Update app.py
Browse files
app.py
CHANGED
@@ -31,35 +31,6 @@ from langchain.chains import LLMChain
|
|
31 |
|
32 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
33 |
|
34 |
-
from googletrans import Translator
|
35 |
-
|
36 |
-
def translate_text(text, source_lang, target_lang):
|
37 |
-
translator = Translator()
|
38 |
-
translated = translator.translate(text, src=source_lang, dest=target_lang)
|
39 |
-
return translated.text
|
40 |
-
|
41 |
-
# Translate English to Tamil
|
42 |
-
english_text = "Hello, how are you?"
|
43 |
-
tamil_text = translate_text(english_text, 'en', 'ta')
|
44 |
-
print("English to Tamil:", tamil_text)
|
45 |
-
|
46 |
-
# Translate Tamil to English
|
47 |
-
tamil_text = "வணக்கம், நீங்கள் எப்படி இருக்கின்றீர்கள்?"
|
48 |
-
english_text = translate_text(tamil_text, 'ta', 'en')
|
49 |
-
print("Tamil to English:", english_text)
|
50 |
-
|
51 |
-
# Translate English to Kannada
|
52 |
-
english_text = "Hello, how are you?"
|
53 |
-
kannada_text = translate_text(english_text, 'en', 'kn')
|
54 |
-
print("English to Kannada:", kannada_text)
|
55 |
-
|
56 |
-
# Translate Kannada to English
|
57 |
-
kannada_text = "ಹಲೋ, ನೀವು ಹೇಗಿದ್ದೀರಿ?"
|
58 |
-
english_text = translate_text(kannada_text, 'kn', 'en')
|
59 |
-
print("Kannada to English:", english_text)
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
def predict(text):
|
64 |
# loader = UnstructuredPDFLoader(file_obj.orig_name)
|
65 |
# data = loader.load()
|
@@ -79,10 +50,23 @@ def predict(text):
|
|
79 |
|
80 |
Question: {question}
|
81 |
Product details:"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
PROMPT = PromptTemplate(
|
83 |
template=prompt_template, input_variables=["question"]
|
84 |
)
|
85 |
-
|
|
|
|
|
|
|
86 |
# qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs)
|
87 |
|
88 |
#Actually, Hi, how are you doing? Actually, I am looking for the hearing aid for my grandfather. He has like age around 62, 65 year old and one of the like major thing that I am looking for the hearing aid product which is like maximum comfort. So if you have anything in that category, so can you please tell me? Thank you.
|
@@ -93,7 +77,11 @@ Product details:"""
|
|
93 |
# template="What is a good name for a company that makes {product}?",
|
94 |
# )
|
95 |
chain = LLMChain(llm=llm, prompt=PROMPT)
|
|
|
|
|
96 |
resp = chain.run(question=text)
|
|
|
|
|
97 |
# print(resp)
|
98 |
|
99 |
# response = []
|
@@ -116,7 +104,7 @@ Product details:"""
|
|
116 |
# html_output += value_html
|
117 |
|
118 |
|
119 |
-
return resp
|
120 |
|
121 |
# def ai(qa,category):
|
122 |
# query = "please suggest "+ category +" interview questions"
|
@@ -195,7 +183,7 @@ def inference(audio, sentiment_option):
|
|
195 |
prediction = predict(result.text)
|
196 |
sentiment_output = display_sentiment_results(sentiment_results, sentiment_option)
|
197 |
|
198 |
-
return lang.upper(), result.text, sentiment_output, prediction
|
199 |
|
200 |
title = """<h1 align="center">🎤 Multilingual ASR 💬</h1>"""
|
201 |
image_path = "thmbnail.jpg"
|
@@ -271,8 +259,11 @@ with block:
|
|
271 |
sentiment_output = gr.Textbox(label="Sentiment Analysis Results", output=True)
|
272 |
|
273 |
prediction = gr.Textbox(label="Prediction")
|
|
|
|
|
|
|
274 |
|
275 |
-
btn.click(inference, inputs=[audio, sentiment_option], outputs=[lang_str, text, sentiment_output, prediction])
|
276 |
|
277 |
# gr.HTML('''
|
278 |
# <div class="footer">
|
|
|
31 |
|
32 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
def predict(text):
|
35 |
# loader = UnstructuredPDFLoader(file_obj.orig_name)
|
36 |
# data = loader.load()
|
|
|
50 |
|
51 |
Question: {question}
|
52 |
Product details:"""
|
53 |
+
|
54 |
+
prompt_template_lang = """
|
55 |
+
You are the world's best languages translator. Will give you some text or paragraph which you have to convert into Tamil, Hindi, Kannada
|
56 |
+
and French.
|
57 |
+
Input Text: {text}
|
58 |
+
Tamil:
|
59 |
+
Hindi:
|
60 |
+
Kannada:
|
61 |
+
French:
|
62 |
+
"""
|
63 |
PROMPT = PromptTemplate(
|
64 |
template=prompt_template, input_variables=["question"]
|
65 |
)
|
66 |
+
PROMPT_lang = PromptTemplate(
|
67 |
+
template=prompt_template_lang, input_variables=["text"]
|
68 |
+
)
|
69 |
+
# chain_type_kwargs = {"prompt": PROMPT}
|
70 |
# qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(), chain_type_kwargs=chain_type_kwargs)
|
71 |
|
72 |
#Actually, Hi, how are you doing? Actually, I am looking for the hearing aid for my grandfather. He has like age around 62, 65 year old and one of the like major thing that I am looking for the hearing aid product which is like maximum comfort. So if you have anything in that category, so can you please tell me? Thank you.
|
|
|
77 |
# template="What is a good name for a company that makes {product}?",
|
78 |
# )
|
79 |
chain = LLMChain(llm=llm, prompt=PROMPT)
|
80 |
+
chain_lang = LLMChain(llm=llm, prompt=PROMPT_lang)
|
81 |
+
|
82 |
resp = chain.run(question=text)
|
83 |
+
resp_lang = chain_lang.run(text=resp)
|
84 |
+
|
85 |
# print(resp)
|
86 |
|
87 |
# response = []
|
|
|
104 |
# html_output += value_html
|
105 |
|
106 |
|
107 |
+
return [resp, resp_lang]
|
108 |
|
109 |
# def ai(qa,category):
|
110 |
# query = "please suggest "+ category +" interview questions"
|
|
|
183 |
prediction = predict(result.text)
|
184 |
sentiment_output = display_sentiment_results(sentiment_results, sentiment_option)
|
185 |
|
186 |
+
return lang.upper(), result.text, sentiment_output, prediction[0], prediction[1]
|
187 |
|
188 |
title = """<h1 align="center">🎤 Multilingual ASR 💬</h1>"""
|
189 |
image_path = "thmbnail.jpg"
|
|
|
259 |
sentiment_output = gr.Textbox(label="Sentiment Analysis Results", output=True)
|
260 |
|
261 |
prediction = gr.Textbox(label="Prediction")
|
262 |
+
|
263 |
+
language_translation = gr.Textbox(label="Language Translation")
|
264 |
+
|
265 |
|
266 |
+
btn.click(inference, inputs=[audio, sentiment_option], outputs=[lang_str, text, sentiment_output, prediction,language_translation])
|
267 |
|
268 |
# gr.HTML('''
|
269 |
# <div class="footer">
|