Add new writing question on generate questions
This commit is contained in:
@@ -1926,7 +1926,6 @@ listening_section_2_to_insert_5 = {
|
|||||||
"section": 2
|
"section": 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# NEW
|
# NEW
|
||||||
reading_to_insert_1 = {
|
reading_to_insert_1 = {
|
||||||
"parts": [
|
"parts": [
|
||||||
@@ -2587,6 +2586,43 @@ reading_to_insert_1 = {
|
|||||||
"type": "academic"
|
"type": "academic"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_writing_to_insert_1 = {
|
||||||
|
"exercises": [
|
||||||
|
{
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prefix": "You should spend about 20 minutes on this task. \\nWrite a letter to your friend who is planning to "
|
||||||
|
"visit your city:",
|
||||||
|
"prompt": "Recommend places to visit and things to do, mention any local events or festivals happening during "
|
||||||
|
"their visit and offer to meet and show them around.",
|
||||||
|
"suffix": "You should write at least 100 words.",
|
||||||
|
"type": "writing",
|
||||||
|
"wordCounter": {
|
||||||
|
"limit": 100,
|
||||||
|
"type": "min"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prefix": "You should spend about 40 minutes on this task.\nPresent a written argument or case to an educated "
|
||||||
|
"reader with no specialist knowledge of the following topic:",
|
||||||
|
"prompt": "Some people believe that technology has made communication between individuals less personal and "
|
||||||
|
"more impersonal. Others argue that technology has improved communication by making it more accessible. "
|
||||||
|
"Discuss both viewpoints and give your own opinion.",
|
||||||
|
"suffix": "You should write at least 250 words.\nUse your own ideas, knowledge and experience and support "
|
||||||
|
"your arguments with examples and relevant evidence.",
|
||||||
|
"type": "writing",
|
||||||
|
"wordCounter": {
|
||||||
|
"limit": 250,
|
||||||
|
"type": "min"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"isDiagnostic": True,
|
||||||
|
"minTimer": 60,
|
||||||
|
"module": "writing",
|
||||||
|
"type": "general"
|
||||||
|
}
|
||||||
|
|
||||||
# Falta section 3 e 4 do listening
|
# Falta section 3 e 4 do listening
|
||||||
# writing task 1 com imagens ...
|
# writing task 1 com imagens ...
|
||||||
# speaking 3 é discussao lol
|
# speaking 3 é discussao lol
|
||||||
@@ -2597,6 +2633,6 @@ db = firestore.client()
|
|||||||
# JSON data to insert
|
# JSON data to insert
|
||||||
|
|
||||||
# Add the JSON data to Firestore
|
# Add the JSON data to Firestore
|
||||||
collection_ref = db.collection('reading')
|
collection_ref = db.collection('writing')
|
||||||
document_ref = collection_ref.add(reading_to_insert_1)
|
document_ref = collection_ref.add(new_writing_to_insert_1)
|
||||||
print(f"Document added with ID: {document_ref}")
|
print(f"Document added with ID: {document_ref}")
|
||||||
|
|||||||
@@ -1,102 +1,174 @@
|
|||||||
|
import random
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
import openai
|
import openai
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from app import GRADING_FIELDS, GRADING_TEMPERATURE
|
||||||
|
from helper.api_messages import get_grading_messages, QuestionType
|
||||||
|
from helper.openai_interface import make_openai_call, process_response
|
||||||
|
from helper.token_counter import count_tokens
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
|
question = "The average standard of people's health is likely to be lower in the future than it is now. To what extent do " \
|
||||||
|
"you agree or disagree with this statement?"
|
||||||
|
answer = "I completely disagree with the written statement. I believe that most of the people in the world have more information " \
|
||||||
|
"about their health and also about how they can improve their healthy conditions. Nowadays, information about " \
|
||||||
|
"how harmful is to smoke for our bodies can be seen in many packets of cigars. This is a clear example how " \
|
||||||
|
"things can change from our recent past. There is a clear trend in the diminishing of smokers and if this " \
|
||||||
|
"continues it will have a positive impact in our health. On the other hand, the alimentation habbits are " \
|
||||||
|
"changing all over the world and this can affect people’s health. However every one can choose what to eat " \
|
||||||
|
"every day. Mostly everybody, from developed societies, know the importance of having a healthy diet. Advances " \
|
||||||
|
"such as the information showed in the menus of fast food restaurants will help people to have a clever choice " \
|
||||||
|
"before they choose what to eat. Another important issue that I would like to mention is how medicine is changing. " \
|
||||||
|
"There are new discovers and treatments almost every week and that is an inequivoque sintom of how things are " \
|
||||||
|
"changing in order to improve the world’s health."
|
||||||
|
|
||||||
def generate_summarizer(
|
# messages = get_grading_messages(QuestionType.WRITING_TASK_2, question, answer)
|
||||||
max_tokens,
|
# token_count = reduce(lambda count, item: count + count_tokens(item)['n_tokens'],
|
||||||
temperature,
|
# map(lambda x: x["content"], filter(lambda x: "content" in x, messages)), 0)
|
||||||
top_p,
|
# response = make_openai_call("gpt-4", messages, token_count, GRADING_FIELDS, GRADING_TEMPERATURE)
|
||||||
frequency_penalty,
|
|
||||||
question_type,
|
grade_wt2_message = "You are a IELTS examiner. " \
|
||||||
question,
|
"The question you have to grade is of type Writing Task 2 and is the following:" + question + \
|
||||||
answer
|
"Assess this answer according to the IELTS grading system. It is mandatory for you to provide your response" \
|
||||||
):
|
" with the overall grade and breakdown grades, with just the following json format: {'comment': 'Comment about " \
|
||||||
res = openai.ChatCompletion.create(
|
"answer quality will go here', 'overall': 7.0, 'task_response': {'Task Achievement': 8.0, " \
|
||||||
model="gpt-3.5-turbo",
|
"'Coherence and Cohesion': 6.5, 'Lexical Resource': 7.5, 'Grammatical Range and Accuracy': 6.0}} " \
|
||||||
max_tokens=int(max_tokens),
|
"Evaluate this answer according to ielts grading system: " + answer
|
||||||
temperature=float(temperature),
|
|
||||||
top_p=float(top_p),
|
|
||||||
frequency_penalty=float(frequency_penalty),
|
|
||||||
messages=
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "You are a IELTS examiner.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": f"The question you have to grade is of type {question_type} and is the following: {question}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"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}}",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "Don't give explanations for the grades, just provide the json with the grades.",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": f"Evaluate this answer according to ielts grading system: {answer}",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
)
|
|
||||||
return res["choices"][0]["message"]["content"]
|
|
||||||
|
|
||||||
|
|
||||||
import streamlit as st
|
topics = [
|
||||||
|
"Art and Creativity",
|
||||||
|
"History of Ancient Civilizations",
|
||||||
|
"Environmental Conservation",
|
||||||
|
"Space Exploration",
|
||||||
|
"Artificial Intelligence",
|
||||||
|
"Climate Change",
|
||||||
|
"World Religions",
|
||||||
|
"The Human Brain",
|
||||||
|
"Renewable Energy",
|
||||||
|
"Cultural Diversity",
|
||||||
|
"Modern Technology Trends",
|
||||||
|
"Women's Rights",
|
||||||
|
"Sustainable Agriculture",
|
||||||
|
"Globalization",
|
||||||
|
"Natural Disasters",
|
||||||
|
"Cybersecurity",
|
||||||
|
"Philosophy of Ethics",
|
||||||
|
"Robotics",
|
||||||
|
"Health and Wellness",
|
||||||
|
"Literature and Classics",
|
||||||
|
"World Geography",
|
||||||
|
"Music and Its Influence",
|
||||||
|
"Human Rights",
|
||||||
|
"Social Media Impact",
|
||||||
|
"Food Sustainability",
|
||||||
|
"Economics and Markets",
|
||||||
|
"Human Evolution",
|
||||||
|
"Political Systems",
|
||||||
|
"Mental Health Awareness",
|
||||||
|
"Quantum Physics",
|
||||||
|
"Biodiversity",
|
||||||
|
"Education Reform",
|
||||||
|
"Animal Rights",
|
||||||
|
"The Industrial Revolution",
|
||||||
|
"Future of Work",
|
||||||
|
"Film and Cinema",
|
||||||
|
"Genetic Engineering",
|
||||||
|
"Ancient Mythology",
|
||||||
|
"Climate Policy",
|
||||||
|
"Space Travel",
|
||||||
|
"Renewable Energy Sources",
|
||||||
|
"Cultural Heritage Preservation",
|
||||||
|
"Modern Art Movements",
|
||||||
|
"Immigration Issues",
|
||||||
|
"Sustainable Transportation",
|
||||||
|
"The History of Medicine",
|
||||||
|
"Artificial Neural Networks",
|
||||||
|
"Climate Adaptation",
|
||||||
|
"Philosophy of Existence",
|
||||||
|
"Augmented Reality",
|
||||||
|
"Yoga and Meditation",
|
||||||
|
"Literary Genres",
|
||||||
|
"World Oceans",
|
||||||
|
"Gender Equality",
|
||||||
|
"Social Networking",
|
||||||
|
"Sustainable Fashion",
|
||||||
|
"International Trade",
|
||||||
|
"Prehistoric Era",
|
||||||
|
"Democracy and Governance",
|
||||||
|
"Postcolonial Literature",
|
||||||
|
"Geopolitics",
|
||||||
|
"Psychology and Behavior",
|
||||||
|
"Nanotechnology",
|
||||||
|
"Endangered Species",
|
||||||
|
"Education Technology",
|
||||||
|
"Renaissance Art",
|
||||||
|
"Renewable Energy Policy",
|
||||||
|
"Cultural Festivals",
|
||||||
|
"Modern Architecture",
|
||||||
|
"Climate Resilience",
|
||||||
|
"Artificial Life",
|
||||||
|
"Fitness and Nutrition",
|
||||||
|
"Classic Literature Adaptations",
|
||||||
|
"World History Wars",
|
||||||
|
"Ethical Dilemmas",
|
||||||
|
"Internet of Things (IoT)",
|
||||||
|
"Meditation Practices",
|
||||||
|
"Literary Symbolism",
|
||||||
|
"Marine Conservation",
|
||||||
|
"Social Justice Movements",
|
||||||
|
"Sustainable Tourism",
|
||||||
|
"International Finance",
|
||||||
|
"Ancient Philosophy",
|
||||||
|
"Cold War Era",
|
||||||
|
"Behavioral Economics",
|
||||||
|
"Space Colonization",
|
||||||
|
"Clean Energy Initiatives",
|
||||||
|
"Cultural Exchange",
|
||||||
|
"Modern Sculpture",
|
||||||
|
"Climate Mitigation",
|
||||||
|
"Artificial Intelligence Ethics",
|
||||||
|
"Mindfulness",
|
||||||
|
"Literary Criticism",
|
||||||
|
"Wildlife Conservation",
|
||||||
|
"Political Activism",
|
||||||
|
"Renewable Energy Innovations",
|
||||||
|
"History of Mathematics",
|
||||||
|
"Human-Computer Interaction",
|
||||||
|
"Global Health",
|
||||||
|
"Cultural Appropriation"
|
||||||
|
]
|
||||||
|
|
||||||
# Set the application title
|
gen_listening2_message = "You are an IELTS program designed to assist with language learning. Your task is to provide a detailed " \
|
||||||
st.title("GPT-3.5 IELTS Examiner")
|
"transcript of a monologue on the subject of " + random.choice(topics) + ". Ensure that the transcript is comprehensive " \
|
||||||
|
"and covers the topic " \
|
||||||
|
"thoroughly.After the transcript, you should generate a fill in the blanks " \
|
||||||
|
"exercise with six statements related to the content of the monologue. The blank spaces in the exercise should " \
|
||||||
|
"be identified by {{number}}. Finally, provide the answers for the exercise." \
|
||||||
|
"Response Format (JSON): { 'transcript': 'Transcript of the monologue on a specific subject with a minimum of 500 words.', 'exercise': {" \
|
||||||
|
"'statements': { '1': 'Statement 1 with a blank space to fill.', '2': 'Statement 2 with a blank space to fill.'," \
|
||||||
|
"'3': 'Statement 3 with a blank space to fill.', '4': 'Statement 4 with a blank space to fill.', " \
|
||||||
|
"'5': 'Statement 5 with a blank space to fill.', '6': 'Statement 6 with a blank space to fill.' }, " \
|
||||||
|
"'answers': { '1': 'Answer to fill the blank space in statement 1.', " \
|
||||||
|
"'2': 'Answer to fill the blank space in statement 2.', '3': 'Answer to fill the blank space in statement 3.'," \
|
||||||
|
"'4': 'Answer to fill the blank space in statement 4.', '5': 'Answer to fill the blank space in statement 5.'," \
|
||||||
|
"'6': 'Answer to fill the blank space in statement 6.' } } }"
|
||||||
|
|
||||||
# qt_col, q_col = st.columns(2)
|
token_count = count_tokens(gen_listening2_message)["n_tokens"]
|
||||||
|
|
||||||
# Selection box to select the question type
|
response = openai.Completion.create(
|
||||||
# with qt_col:
|
model="gpt-3.5-turbo-instruct",
|
||||||
question_type = st.selectbox(
|
prompt=gen_listening2_message,
|
||||||
"What is the question type?",
|
max_tokens=int(4097 - token_count - 300),
|
||||||
(
|
temperature=0.7
|
||||||
"Listening",
|
)["choices"][0]["text"]
|
||||||
"Reading",
|
|
||||||
"Writing Task 1",
|
|
||||||
"Writing Task 2",
|
|
||||||
"Speaking Part 1",
|
|
||||||
"Speaking Part 2"
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Provide the input area for question to be answered
|
# processed = process_response(response, "comment")
|
||||||
# with q_col:
|
processed = process_response(response, "transcript")
|
||||||
question = st.text_area("Enter the question:", height=100)
|
print(processed)
|
||||||
|
|
||||||
# Provide the input area for text to be summarized
|
|
||||||
answer = st.text_area("Enter the answer:", 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(token, temp, top_p, f_pen, question_type, question, answer))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user