Spaces:
Build error
Build error
| 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.") | |