first commit
This commit is contained in:
1
.env
Normal file
1
.env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
OPENAI_API_KEY=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
|
||||||
2
.idea/flaskProject.iml → .idea/ielts-be.iml
generated
2
.idea/flaskProject.iml → .idea/ielts-be.iml
generated
@@ -7,7 +7,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TemplatesService">
|
<component name="TemplatesService">
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (flaskProject)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@@ -2,7 +2,7 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/flaskProject.iml" filepath="$PROJECT_DIR$/.idea/flaskProject.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/ielts-be.iml" filepath="$PROJECT_DIR$/.idea/ielts-be.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
35
app.py
35
app.py
@@ -1,12 +1,41 @@
|
|||||||
|
import openai
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello_world(): # put application's code here
|
def generate_summarizer(
|
||||||
return 'Hello World!'
|
max_tokens,
|
||||||
|
temperature,
|
||||||
|
top_p,
|
||||||
|
frequency_penalty,
|
||||||
|
prompt,
|
||||||
|
person_type,
|
||||||
|
):
|
||||||
|
res = openai.ChatCompletion.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
max_tokens=100,
|
||||||
|
temperature=0.7,
|
||||||
|
top_p=0.5,
|
||||||
|
frequency_penalty=0.5,
|
||||||
|
messages=
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "You are a helpful assistant for text summarization.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": f"Summarize this for a {person_type}: {prompt}",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
return res["choices"][0]["message"]["content"]
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run()
|
app.run()
|
||||||
|
|||||||
102
playground.py
Normal file
102
playground.py
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import openai
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
|
|
||||||
|
def generate_summarizer(
|
||||||
|
max_tokens,
|
||||||
|
temperature,
|
||||||
|
top_p,
|
||||||
|
frequency_penalty,
|
||||||
|
question_type,
|
||||||
|
question,
|
||||||
|
answer
|
||||||
|
):
|
||||||
|
res = openai.ChatCompletion.create(
|
||||||
|
model="gpt-3.5-turbo",
|
||||||
|
max_tokens=int(max_tokens),
|
||||||
|
temperature=float(temperature),
|
||||||
|
top_p=float(top_p),
|
||||||
|
frequency_penalty=float(frequency_penalty),
|
||||||
|
messages=
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": "You are a IELTS examiner.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"content": f"The question you have to grade is of type {question_type} and is the following: {question}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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}}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "system",
|
||||||
|
"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
|
||||||
|
|
||||||
|
# Set the application title
|
||||||
|
st.title("GPT-3.5 IELTS Examiner")
|
||||||
|
|
||||||
|
# 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?",
|
||||||
|
(
|
||||||
|
"Listening",
|
||||||
|
"Reading",
|
||||||
|
"Writing Task 1",
|
||||||
|
"Writing Task 2",
|
||||||
|
"Speaking Part 1",
|
||||||
|
"Speaking Part 2"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Provide the input area for question to be answered
|
||||||
|
# with q_col:
|
||||||
|
question = st.text_area("Enter the question:", height=100)
|
||||||
|
|
||||||
|
# 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