# This is an example of integrating a LLM with streamlit
import streamlit as st
import os
import openai
import langchain
from langchain.llms import OpenAI
from langchain import PromptTemplate
#from dotenv import load_dotenv

# Specify the path to the .env file
#dotenv_path = os.path.join(os.path.dirname(__file__), '.env')

# Load the .env file
#load_dotenv(dotenv_path)

# Streamlit Code
st.set_page_config(page_title="Globalize Email", page_icon = ":robot:")
st.header("Globalize Text")

# LLM Code
template = """
    Below is an email that is poorly worded.
    Your goal is to:
    - Properly format the email
    - Convert the input text to a specified tone
    - Convert the input text to a specified dialect
    
    Here are some examples of different Tones:
    - Formal: We went to Barcelona for the weekend. We have a lot of things to tell you.
    - Information: Went to Barcelona for the weekend. Lots to tell you.
    
    Here are some examples of words in different dialects:
    - American English: French Fries, cotton candy, apartment, garbage cookie
    - British English: chips, candyfloss, flag, rubbish, biscuit
    
    Below is the email, tone, and dialect:
    TONE: {tone}
    DIALECT: {dialect}
    EMAIL: {email}
    
    YOUR RESPONSE:
"""
prompt = PromptTemplate(
    input_variables=["tone", "dialect", "email"],
    template = template,
)

llm = OpenAI(temperature = .5)

col1, col2 = st. columns(2)

with col1:
    st.markdown("This application is a demo of the SRL chatbot being developed between UCATT and UAHS International")

with col2:
    st.image(image='screenshot.png', width=500, caption="Screenshot of source video")

st.markdown("## Enter Your Email to Convert")

col1, col2 = st.columns(2)
with col1:
    option_tone = st.selectbox(
        'Which tone would you like your email to have?',
        ('Formal', 'Informal'))
    
with col2:
    option_dialect = st.selectbox(
        'Which English Dialect would you like?',
        ('American English', 'British English')
    )

def get_text():
    input_text = st.text_area(label="", placeholder = "Your email...", key="email_input")
    return input_text

email_input = get_text()

st.markdown("### Your Converted Email:")

if email_input:
    prompt_with_email = prompt.format(tone = option_tone, dialect = option_dialect, email = email_input)
    
    # See full prompt
    #st.write(prompt_with_email)

    formatted_email = llm(prompt_with_email)

    st.write(formatted_email)

langchain.llms.OpenAI langchain.PromptTemplate
[((390, 459), 'streamlit.set_page_config', 'st.set_page_config', ([], {'page_title': '"""Globalize Email"""', 'page_icon': '""":robot:"""'}), "(page_title='Globalize Email', page_icon=':robot:')\n", (408, 459), True, 'import streamlit as st\n'), ((462, 489), 'streamlit.header', 'st.header', (['"""Globalize Text"""'], {}), "('Globalize Text')\n", (471, 489), True, 'import streamlit as st\n'), ((1280, 1359), 'langchain.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['tone', 'dialect', 'email']", 'template': 'template'}), "(input_variables=['tone', 'dialect', 'email'], template=template)\n", (1294, 1359), False, 'from langchain import PromptTemplate\n'), ((1380, 1403), 'langchain.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0.5)'}), '(temperature=0.5)\n', (1386, 1403), False, 'from langchain.llms import OpenAI\n'), ((1419, 1432), 'streamlit.columns', 'st.columns', (['(2)'], {}), '(2)\n', (1429, 1432), True, 'import streamlit as st\n'), ((1663, 1708), 'streamlit.markdown', 'st.markdown', (['"""## Enter Your Email to Convert"""'], {}), "('## Enter Your Email to Convert')\n", (1674, 1708), True, 'import streamlit as st\n'), ((1723, 1736), 'streamlit.columns', 'st.columns', (['(2)'], {}), '(2)\n', (1733, 1736), True, 'import streamlit as st\n'), ((2179, 2219), 'streamlit.markdown', 'st.markdown', (['"""### Your Converted Email:"""'], {}), "('### Your Converted Email:')\n", (2190, 2219), True, 'import streamlit as st\n'), ((1450, 1573), 'streamlit.markdown', 'st.markdown', (['"""This application is a demo of the SRL chatbot being developed between UCATT and UAHS International"""'], {}), "(\n    'This application is a demo of the SRL chatbot being developed between UCATT and UAHS International'\n    )\n", (1461, 1573), True, 'import streamlit as st\n'), ((1580, 1666), 'streamlit.image', 'st.image', ([], {'image': '"""screenshot.png"""', 'width': '(500)', 'caption': '"""Screenshot of source video"""'}), "(image='screenshot.png', width=500, caption=\n    'Screenshot of source video')\n", (1588, 1666), True, 'import streamlit as st\n'), ((1766, 1855), 'streamlit.selectbox', 'st.selectbox', (['"""Which tone would you like your email to have?"""', "('Formal', 'Informal')"], {}), "('Which tone would you like your email to have?', ('Formal',\n    'Informal'))\n", (1778, 1855), True, 'import streamlit as st\n'), ((1906, 2004), 'streamlit.selectbox', 'st.selectbox', (['"""Which English Dialect would you like?"""', "('American English', 'British English')"], {}), "('Which English Dialect would you like?', ('American English',\n    'British English'))\n", (1918, 2004), True, 'import streamlit as st\n'), ((2057, 2127), 'streamlit.text_area', 'st.text_area', ([], {'label': '""""""', 'placeholder': '"""Your email..."""', 'key': '"""email_input"""'}), "(label='', placeholder='Your email...', key='email_input')\n", (2069, 2127), True, 'import streamlit as st\n'), ((2453, 2478), 'streamlit.write', 'st.write', (['formatted_email'], {}), '(formatted_email)\n', (2461, 2478), True, 'import streamlit as st\n')]