Abhinay23 commited on
Commit
0e55616
1 Parent(s): ae98dd4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_openai import ChatOpenAI
2
+ from langchain_core.prompts import ChatPromptTemplate
3
+ import streamlit as st
4
+ import os
5
+ import openai
6
+
7
+
8
+
9
+
10
+ openai_api_k = os.getenv("openai_key")
11
+
12
+
13
+ llm = ChatOpenAI(temperature=0, model="gpt-3.5-turbo",openai_api_key=openai_api_k)
14
+
15
+
16
+ prompt = ChatPromptTemplate.from_messages([
17
+ ("system", "You are a helpful assistant that translates {il} to {ol}."),
18
+ ("human", "{input}")
19
+ ])
20
+
21
+
22
+ st.title("Language Translator")
23
+
24
+
25
+ input_language = st.text_input("Input Language")
26
+ output_language = st.text_input("Output Language")
27
+ input_text = st.text_area("Input Text:", height=100)
28
+
29
+
30
+ if st.button("Translate"):
31
+ if input_language and output_language and input_text:
32
+ chain = prompt | llm
33
+ response = chain.invoke({
34
+ "il": input_language,
35
+ "ol": output_language,
36
+ "input": input_text
37
+ })
38
+ st.text_area("Translated Text:", value=response.content, height=100)