text-correction / app.py
heysho's picture
Create app.py
a4bd41d verified
raw
history blame
2.13 kB
import streamlit as st
import openai
ai_model = "gpt-4-turbo"
token = 4096
# Set the page title and favicon
st.set_page_config(page_title="Text Correction", page_icon=":bar_chart:")
openai.api_key = st.secrets['OPENAI_API_KEY']
st.title('Sentence Correction')
if 'usage_count' not in st.session_state:
st.session_state['usage_count'] = 0 # Usage counter
max_uses = 3
if st.session_state['usage_count'] < max_uses:
# Main Contents Start from here -------------------------------
st.subheader('English')
en_input = st.text_area("Enter your English text here:", key="en_input")
if st.button("Correct", key="en_correction"):
st.session_state['usage_count'] += 1 # Increment the usage counter
# Create a prompt based on the user input
en_prompt = f"Correct the following English sentence. The output language should be English. Here is the text: {en_input}"
# Make a request to the API to generate text
en_response = openai.ChatCompletion.create(
model=ai_model, # Use the engine of your choice
messages=[{"role": "user", "content": en_prompt}],
max_tokens=token
)
st.write(en_response["choices"][0]["message"]["content"])
st.text(" ")
st.text(" ")
st.subheader('ζ—₯本θͺž')
ja_input = st.text_area("ζ—₯本θͺžγ‚’ε…₯εŠ›γγ γ•γ„", key="ja_input")
if st.button("树正する", key="ja_correction"):
st.session_state['usage_count'] += 1 # Increment the usage counter
# Create a prompt based on the user input
ja_prompt = f"Correct the following Japanese sentence. The output language should be Japanese. Here is the text: {ja_input}"
# Make a request to the API to generate text
ja_response = openai.ChatCompletion.create(
model=ai_model, # Use the engine of your choice
messages=[{"role": "user", "content": ja_prompt}],
max_tokens=token
)
st.write(ja_response["choices"][0]["message"]["content"])
else:
st.error("You have reached your maximum usage limit.")