|
import streamlit as st |
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
import torch |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("MohamedMotaz/Examination-llama-8b-4bit") |
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained( |
|
"MohamedMotaz/Examination-llama-8b-4bit", |
|
torch_dtype=torch.float32, |
|
device_map="cpu", |
|
) |
|
|
|
|
|
st.title("Exam Corrector: Automated Grading with LLama 8b Model (CPU)") |
|
|
|
|
|
st.markdown(""" |
|
### Instructions: |
|
- Enter both the **Model Answer** and the **Student Answer**. |
|
- Click on the **Grade Answer** button to get the grade and explanation. |
|
""") |
|
|
|
|
|
model_answer = st.text_area("Model Answer", "The process of photosynthesis involves converting light energy into chemical energy.") |
|
student_answer = st.text_area("Student Answer", "Photosynthesis is when plants turn light into energy.") |
|
|
|
|
|
if st.button("Grade Answer"): |
|
|
|
inputs = f"Model Answer: {model_answer}\n\nStudent Answer: {student_answer}\n\nResponse:" |
|
|
|
|
|
input_ids = tokenizer(inputs, return_tensors="pt").input_ids |
|
|
|
|
|
with torch.no_grad(): |
|
outputs = model.generate(input_ids, max_length=200) |
|
|
|
|
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
|
|
|
|
st.subheader("Grading Results") |
|
st.write(response) |
|
|
|
|
|
st.markdown(""" |
|
--- |
|
**App created by [Engr. Hamesh Raj](https://www.linkedin.com/in/hamesh-raj)** |
|
""") |