Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_openai import ChatOpenAI
|
| 3 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
os.environ["OPENAI_API_KEY"] = os.getenv("k1")
|
| 7 |
+
|
| 8 |
+
st.title("Language Processing Application :robot_face:")
|
| 9 |
+
|
| 10 |
+
# Sidebar for task selection
|
| 11 |
+
task = st.sidebar.selectbox("Choose a task:", ["Translation", "Summarization"])
|
| 12 |
+
|
| 13 |
+
# Tabs for multiple pages
|
| 14 |
+
tab1, tab2 = st.tabs(["Page 1", "Page 2"])
|
| 15 |
+
|
| 16 |
+
with tab1:
|
| 17 |
+
if task == "Translation":
|
| 18 |
+
st.header("Translation Task")
|
| 19 |
+
options1 = ["English", "Telugu", "Hindi", "French", "German", "Russian", "Spanish"]
|
| 20 |
+
input_language = st.selectbox("Input Language: ", options1)
|
| 21 |
+
|
| 22 |
+
options2 = ["Hindi", "Telugu", "Spanish", "English", "German", "Russian", "French"]
|
| 23 |
+
output_language = st.selectbox("Output Language: ", options2)
|
| 24 |
+
|
| 25 |
+
text = st.text_input("Text Input: ")
|
| 26 |
+
|
| 27 |
+
if st.button("Submit Translation"):
|
| 28 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
| 29 |
+
|
| 30 |
+
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for translation from {il} to {ol}"),
|
| 31 |
+
("human", "{i}")])
|
| 32 |
+
|
| 33 |
+
chain = prompt | llm
|
| 34 |
+
|
| 35 |
+
response = chain.invoke({"il": input_language, "ol": output_language, "i": text})
|
| 36 |
+
|
| 37 |
+
st.write("Response: ")
|
| 38 |
+
st.write(response.content)
|
| 39 |
+
|
| 40 |
+
elif task == "Summarization":
|
| 41 |
+
st.header("Summarization Task")
|
| 42 |
+
text = st.text_area("Text Input for Summarization: ")
|
| 43 |
+
|
| 44 |
+
if st.button("Submit Summarization"):
|
| 45 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
| 46 |
+
|
| 47 |
+
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for summarization"),
|
| 48 |
+
("human", "Summarize the following text: {i}")])
|
| 49 |
+
|
| 50 |
+
chain = prompt | llm
|
| 51 |
+
|
| 52 |
+
response = chain.invoke({"i": text})
|
| 53 |
+
|
| 54 |
+
st.write("Response: ")
|
| 55 |
+
st.write(response.content)
|
| 56 |
+
|
| 57 |
+
with tab2:
|
| 58 |
+
if task == "Translation":
|
| 59 |
+
st.header("Translation Task")
|
| 60 |
+
# Repeat the same structure for additional pages if needed
|
| 61 |
+
options1 = ["English", "Telugu", "Hindi", "French", "German", "Russian", "Spanish"]
|
| 62 |
+
input_language = st.selectbox("Input Language: ", options1, key='input_lang2')
|
| 63 |
+
|
| 64 |
+
options2 = ["Hindi", "Telugu", "Spanish", "English", "German", "Russian", "French"]
|
| 65 |
+
output_language = st.selectbox("Output Language: ", options2, key='output_lang2')
|
| 66 |
+
|
| 67 |
+
text = st.text_input("Text Input: ", key='text_input2')
|
| 68 |
+
|
| 69 |
+
if st.button("Submit Translation", key='submit_translation2'):
|
| 70 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
| 71 |
+
|
| 72 |
+
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for translation from {il} to {ol}"),
|
| 73 |
+
("human", "{i}")])
|
| 74 |
+
|
| 75 |
+
chain = prompt | llm
|
| 76 |
+
|
| 77 |
+
response = chain.invoke({"il": input_language, "ol": output_language, "i": text})
|
| 78 |
+
|
| 79 |
+
st.write("Response: ")
|
| 80 |
+
st.write(response.content)
|
| 81 |
+
|
| 82 |
+
elif task == "Summarization":
|
| 83 |
+
st.header("Summarization Task")
|
| 84 |
+
text = st.text_area("Text Input for Summarization: ", key='text_area2')
|
| 85 |
+
|
| 86 |
+
if st.button("Submit Summarization", key='submit_summarization2'):
|
| 87 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
|
| 88 |
+
|
| 89 |
+
prompt = ChatPromptTemplate.from_messages([("system", "you are a good assistant for summarization"),
|
| 90 |
+
("human", "Summarize the following text: {i}")])
|
| 91 |
+
|
| 92 |
+
chain = prompt | llm
|
| 93 |
+
|
| 94 |
+
response = chain.invoke({"i": text})
|
| 95 |
+
|
| 96 |
+
st.write("Response: ")
|
| 97 |
+
st.write(response.content)
|