Spaces:
Sleeping
Sleeping
import streamlit as st | |
from streamlit import session_state | |
import os | |
import openai | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
import pandas as pd | |
from sklearn.preprocessing import LabelEncoder | |
import numpy as np | |
def gpt4_score(m_answer, s_answer): | |
response = openai.ChatCompletion.create( | |
model="gpt-4", | |
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. \n<<REMEMBER>>\nIt is 10 marks question. Student can recieve maximum 5 marks. Give marks in the range of 0.25. (ex. 0,0.25,0.5...)\nThere are 3 parts in the answer. Introduction (1 marks), body (3 marks) and conclusion (1 marks). If the student answer and model answer is not relevant then give 0 marks.\ngive output in json form. Give output in this format {\"intro\":,\"body\":,\"con\":,\"total\":}\n<<OUTPUT>>\n" | |
}, | |
{ | |
"role": "assistant", | |
"content": f"Model answer: {m_answer}"}, | |
{ | |
"role": "user", | |
"content": f"Student answer: {s_answer}"} | |
], | |
temperature=0, | |
max_tokens=701, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
return response.choices[0].message.content | |
st.write("# Auto Score Generation! 👋") | |
if 'score' not in session_state: | |
session_state['score']= "" | |
text1= st.text_area(label= "Please write the Model Answer bellow", | |
placeholder="What does the text say?") | |
text2= st.text_area(label= "Please write the Student Answer bellow", | |
placeholder="What does the text say?") | |
def classify(text1,text2): | |
session_state['score'] = gpt4_score(text1,text2) | |
st.text_area("result", value=session_state['score']) | |
st.button("Classify", on_click=classify, args=[text1,text2]) |