File size: 3,807 Bytes
8bd83e4 |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
import os
os.environ["OPENAI_API_KEY"] = os.getenv("k1")
st.title("Language Processing Application :robot_face:")
# Sidebar for task selection
task = st.sidebar.selectbox("Choose a task:", ["Translation", "Summarization"])
# Tabs for multiple pages
tab1, tab2 = st.tabs(["Page 1", "Page 2"])
with tab1:
if task == "Translation":
st.header("Translation Task")
options1 = ["English", "Telugu", "Hindi", "French", "German", "Russian", "Spanish"]
input_language = st.selectbox("Input Language: ", options1)
options2 = ["Hindi", "Telugu", "Spanish", "English", "German", "Russian", "French"]
output_language = st.selectbox("Output Language: ", options2)
text = st.text_input("Text Input: ")
if st.button("Submit Translation"):
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for translation from {il} to {ol}"),
("human", "{i}")])
chain = prompt | llm
response = chain.invoke({"il": input_language, "ol": output_language, "i": text})
st.write("Response: ")
st.write(response.content)
elif task == "Summarization":
st.header("Summarization Task")
text = st.text_area("Text Input for Summarization: ")
if st.button("Submit Summarization"):
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for summarization"),
("human", "Summarize the following text: {i}")])
chain = prompt | llm
response = chain.invoke({"i": text})
st.write("Response: ")
st.write(response.content)
with tab2:
if task == "Translation":
st.header("Translation Task")
# Repeat the same structure for additional pages if needed
options1 = ["English", "Telugu", "Hindi", "French", "German", "Russian", "Spanish"]
input_language = st.selectbox("Input Language: ", options1, key='input_lang2')
options2 = ["Hindi", "Telugu", "Spanish", "English", "German", "Russian", "French"]
output_language = st.selectbox("Output Language: ", options2, key='output_lang2')
text = st.text_input("Text Input: ", key='text_input2')
if st.button("Submit Translation", key='submit_translation2'):
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for translation from {il} to {ol}"),
("human", "{i}")])
chain = prompt | llm
response = chain.invoke({"il": input_language, "ol": output_language, "i": text})
st.write("Response: ")
st.write(response.content)
elif task == "Summarization":
st.header("Summarization Task")
text = st.text_area("Text Input for Summarization: ", key='text_area2')
if st.button("Submit Summarization", key='submit_summarization2'):
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for summarization"),
("human", "Summarize the following text: {i}")])
chain = prompt | llm
response = chain.invoke({"i": text})
st.write("Response: ")
st.write(response.content)
|