File size: 1,176 Bytes
3283702
082bd98
 
6f718c8
082bd98
5afdb81
6aa16fa
082bd98
 
 
 
 
6f718c8
22cd40f
 
 
 
 
 
 
 
 
 
6f718c8
082bd98
 
6f718c8
22cd40f
 
 
 
 
 
 
 
 
 
082bd98
 
f55a250
082bd98
6f718c8
 
 
 
082bd98
6f718c8
082bd98
6aa16fa
 
6f718c8
 
 
 
 
 
6aa16fa
6f718c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
from langchain_openai import ChatOpenAI
import os
from langchain.prompts import ChatPromptTemplate

os.environ['OPENAI_API_KEY'] = os.getenv('api_key')

llm = ChatOpenAI(model='gpt-3.5-turbo', temperature=0, max_tokens=150)

st.header("Translation Application")

il = st.selectbox(
    "Please select the input language",
    ("Hindi",
    "Bengali",
    "Marathi",
    "Telugu",
    "Tamil",
    "Gujarati",
    "Urdu",
    "Kannada",
    "Odia",
    "Malayalam")
)

ol = st.selectbox(
    "Please select the output language",
    ("Hindi",
    "Bengali",
    "Marathi",
    "Telugu",
    "Tamil",
    "Gujarati",
    "Urdu",
    "Kannada",
    "Odia",
    "Malayalam")
)

input_text = st.text_area('Input Text', height=100)

prompt = ChatPromptTemplate.from_messages(
    [('system', 'You are a good assistant for translation from {il} to {ol}'),
     ('user', '{i}')]
)

chain = prompt | llm

if st.button('Submit'):
    if input_text:
        response = chain.invoke({
            'il': il,
            'ol': ol,
            'i': input_text
        })
        st.write(response.content)
    else:
        st.write('Please enter text to translate.')