Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +55 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import google.generativeai as genai
|
3 |
+
import os
|
4 |
+
import PyPDF2 as pdf
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import json
|
7 |
+
|
8 |
+
load_dotenv() ## load all our environment variables
|
9 |
+
|
10 |
+
os.getenv("GOOGLE_API_KEY")
|
11 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
def get_gemini_response(input):
|
16 |
+
model=genai.GenerativeModel('gemini-pro')
|
17 |
+
response=model.generate_content(input)
|
18 |
+
return response.text
|
19 |
+
|
20 |
+
def input_pdf_text(uploaded_file):
|
21 |
+
reader=pdf.PdfReader(uploaded_file)
|
22 |
+
text=""
|
23 |
+
for page in range(len(reader.pages)):
|
24 |
+
page=reader.pages[page]
|
25 |
+
text+=str(page.extract_text())
|
26 |
+
return text
|
27 |
+
|
28 |
+
#Prompt Template
|
29 |
+
|
30 |
+
input_prompt="""
|
31 |
+
Act Like a skilled or very experience Teacher. Your task is to evaluate the answers in the test. You are a very very strict teacher. Here are the details:-
|
32 |
+
Questions:{qs}
|
33 |
+
Answers:{text}
|
34 |
+
Rubric: {ٍrubric}
|
35 |
+
Give your response in 4 seperate parts having the structure
|
36 |
+
Marks:"%"
|
37 |
+
Give a small message saying 'Good Job' or something based on percentage
|
38 |
+
MissingKeywords:[]
|
39 |
+
Tips to Improve the Student Marks:""}}
|
40 |
+
"""
|
41 |
+
|
42 |
+
## streamlit app
|
43 |
+
st.title("AI AutoGrader")
|
44 |
+
qs=st.text_area("Enter Test Questions")
|
45 |
+
rubric=st.text_area("Enter Test Rubric")
|
46 |
+
uploaded_file=st.file_uploader("Upload Answer Sheet",type="pdf",help="Please uplaod the pdf")
|
47 |
+
|
48 |
+
submit = st.button("Submit")
|
49 |
+
|
50 |
+
if submit:
|
51 |
+
if uploaded_file is not None:
|
52 |
+
text=input_pdf_text(uploaded_file)
|
53 |
+
response=get_gemini_response(input_prompt.format(text=text, qs=qs, rubric=rubric))
|
54 |
+
st.subheader(response)
|
55 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|
4 |
+
langchain
|
5 |
+
PyPDF2
|
6 |
+
chromadb
|
7 |
+
pdf2image
|
8 |
+
langchain_google_genai
|