Spaces:
Sleeping
Sleeping
| 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.') | |