import streamlit as st import openai import os from dotenv import load_dotenv load_dotenv() openai.api_key = os.getenv("OPENAI_API_KEY") def generate_summarizer( temperature, question_type, content ): res = openai.ChatCompletion.create( model="gpt-3.5-turbo", temperature=float(temperature), messages=[ { "role": "system", "content": "You are a IELTS exam question generation program.", }, { "role": "system", "content": f"Generate a simple {question_type} for the following text: {content}", }, { "role": "system", "content": "Please provide a JSON object response with the overall grade and breakdown grades, " "formatted as follows: {'overall': 7.0, 'task_response': {'Task Achievement': 8.0, " "'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': " "6.0}}", }, ], ) return res["choices"][0]["message"]["content"] # Set the application title st.title("GPT-3.5 IELTS Question Generation Program") # qt_col, q_col = st.columns(2) # Selection box to select the question type # with qt_col: question_type = st.selectbox( "What is the question type?", ( "Writing Task 2", ), ) # Provide the input area for question to be answered # with q_col: content = st.text_area("Enter the content:", height=100) # Initiate two columns for section to be side-by-side # col1, col2 = st.columns(2) # Slider to control the model hyperparameter # with col1: # token = st.slider("Token", min_value=0.0, # max_value=2000.0, value=1000.0, step=1.0) temp = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.01) # top_p = st.slider("Top_p", min_value=0.0, max_value=1.0, value=0.9, step=0.01) # f_pen = st.slider("Frequency Penalty", min_value=-1.0, # max_value=1.0, value=0.5, step=0.01) # Showing the current parameter used for the model # with col2: with st.expander("Current Parameter"): # st.write("Current Token :", token) st.write("Current Temperature :", temp) # st.write("Current Nucleus Sampling :", top_p) # st.write("Current Frequency Penalty :", f_pen) # Creating button for execute the text summarization if st.button("Grade"): st.write(generate_summarizer(temp, question_type, content))