sunny333 commited on
Commit
5109101
·
unverified ·
1 Parent(s): 6dfd551

adding app.py and utility

Browse files
Files changed (2) hide show
  1. app.py +17 -0
  2. utility.py +38 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import utility as ut
3
+ def selectLanguage(EnterText,selectLanguage):
4
+ res= ut.translateIt(EnterText,"English",selectLanguage)
5
+ return res.content
6
+ demo = gr.Interface(
7
+
8
+ title="I am a language translator",
9
+ fn=selectLanguage,
10
+
11
+ inputs=["text",gr.Radio(["Hindi","French","Spanish"])],
12
+ outputs=["text"],
13
+
14
+
15
+ )
16
+
17
+ demo.launch()
utility.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_groq import ChatGroq
2
+ from langchain_core.prompts import ChatPromptTemplate
3
+ import os
4
+ from dotenv import load_dotenv
5
+ os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
6
+
7
+ llm = ChatGroq(
8
+ model="mixtral-8x7b-32768",
9
+ temperature=0,
10
+ max_tokens=None,
11
+ timeout=None,
12
+ max_retries=2
13
+
14
+ )
15
+
16
+ def translateIt(text,inputLang,outputLang):
17
+ prompt = ChatPromptTemplate.from_messages(
18
+ [
19
+ ("system",
20
+ "You are a helpful assistant that translates {input_language} to {output_language}."
21
+ ),
22
+ ("human","{input}")
23
+ ]
24
+ )
25
+ chain = prompt | llm
26
+
27
+ res = chain.invoke({
28
+ "input_language":inputLang,
29
+ "output_language":outputLang,
30
+
31
+ "input":text,
32
+ })
33
+ return res
34
+ #r= translateIt("i love you","English","Hindi")
35
+ #print(r.content)
36
+
37
+
38
+