themeetjani commited on
Commit
ac0affd
·
verified ·
1 Parent(s): 0bd2122

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ import streamlit as st
3
+ from streamlit import session_state
4
+ client = OpenAI()
5
+ openai.api_key = os.getenv("OPENAI_API_KEY")
6
+ def score(m,s):
7
+ response = client.chat.completions.create(
8
+ model="gpt-4",
9
+ messages=[
10
+ {
11
+ "role": "system",
12
+ "content": "You are a Grading assistant. Your task is to give marks to the student answers based on the model answer. You will be provided student answer and model answer. Please check both carefully and give marks out of 10. \n\n<<REMEMBER>>\nThese answers are written by High school kids. Don't be too strict. Give marks generously. \nGive marks in the range of 0.5. \nIf the model answer and student answer is slightly matching then give marks generously. Please give output in json format like this:\n{\"output\":5}"
13
+ },
14
+ {
15
+ "role": "user",
16
+ "content": f"Model answer: {m}"},
17
+ {
18
+ "role": "user",
19
+ "content": f"Student answer: {s}"
20
+ }
21
+ ],
22
+ temperature=0,
23
+ max_tokens=256,
24
+ top_p=1,
25
+ frequency_penalty=0,
26
+ presence_penalty=0
27
+ )
28
+ return response.choices[0].message.content
29
+
30
+ from st_pages import Page, Section, show_pages, add_page_title,add_indentation
31
+ st.set_page_config(page_title="Auto score Openai", page_icon="📈")
32
+
33
+ st.markdown("<h1 style='text-align: center; color: black;'> Welcome to Our App! 👋</h1>", unsafe_allow_html=True)
34
+
35
+ if 'result' not in session_state:
36
+ session_state['result']= ""
37
+
38
+ st.title("Auto score")
39
+ text1= st.text_area(label= "Please write the text bellow",
40
+ placeholder="What does the tweet say?")
41
+ text2= st.text_area(label= "Please write the text bellow",
42
+ placeholder="What does the tweet say?")
43
+ def classify(text):
44
+ session_state['result'] = score(text1,text2)
45
+
46
+
47
+ st.text_area("result", value=session_state['result'])
48
+
49
+ st.button("Classify", on_click=classify, args=[text1,text2])