NCRTAutoScore / app.py
themeetjani's picture
Update app.py
707e31a verified
import openai
from openai import OpenAI
import streamlit as st
from streamlit import session_state
import os
client = OpenAI()
openai.api_key = os.getenv("OPENAI_API_KEY")
def score(m,s):
response = client.chat.completions.create(
model="gpt-4-0125-preview",
messages=[
{
"role": "system",
"content": "You are UPSC answers evaluater. You will be given model answer and student answer. Evaluate it by comparing with the model answer and give marks. Also provide 2 comments about the student answer in short. \n<<REMEMBER>>\nIt is 10 marks question. Give marks in the range of 0.5. (ex. 0,0.5,1...)\nPlease give marks generously. If the student answer body matches more than 60% with the model answer then give full marks for body. \nIf the student answer and model answer is not relevant then give 0 marks.\ngive output in json format. Give output in this format {\"total\":,\"comments\":[comment1, comment2]}\n<<OUTPUT>>"
},
{
"role": "user",
"content": f"Model answer: {m}"},
{
"role": "user",
"content": f"Student answer: {s}"
}
],
temperature=0,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content
from st_pages import Page, Section, show_pages, add_page_title,add_indentation
st.set_page_config(page_title="Auto score Openai", page_icon="πŸ“ˆ")
st.markdown("<h1 style='text-align: center; color: black;'> Welcome to Our App! πŸ‘‹</h1>", unsafe_allow_html=True)
if 'result' not in session_state:
session_state['result']= ""
st.title("Auto score")
text1= st.text_area(label= "Please write the model answer bellow",
placeholder="What does the teacher say?")
text2= st.text_area(label= "Please write the student answer bellow",
placeholder="What does the student say?")
def classify(text1,text2):
session_state['result'] = score(text1,text2)
st.text_area("result", value=session_state['result'])
st.button("Classify", on_click=classify, args=[text1,text2])