Update app.py
Browse files
app.py
CHANGED
@@ -7,32 +7,14 @@ from PIL import Image
|
|
7 |
import pytesseract as tess
|
8 |
from sentence_transformers import SentenceTransformer, util
|
9 |
import io
|
|
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
# tokenizer = AutoTokenizer.from_pretrained(save_directory)
|
15 |
|
16 |
-
# # Load the model from the saved directory
|
17 |
-
# model = AutoModelForCausalLM.from_pretrained(
|
18 |
-
# save_directory,
|
19 |
-
# torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
20 |
-
# device_map="auto" if torch.cuda.is_available() else None
|
21 |
-
# )
|
22 |
-
|
23 |
-
# # Move model to the appropriate device (CPU or CUDA)
|
24 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
25 |
-
# model.to(device)
|
26 |
-
|
27 |
-
# print(f"Model and tokenizer loaded from {save_directory}")
|
28 |
-
|
29 |
-
tess.pytesseract.tesseract_cmd = r"tesseract"
|
30 |
-
|
31 |
-
# Use a pipeline as a high-level helper
|
32 |
-
# pipe = pipeline("text-generation", model="eachadea/vicuna-7b-1.1")
|
33 |
-
|
34 |
-
# Initialize the pipeline with the Hugging Face API
|
35 |
-
# pipe = pipeline("text-generation", model="eachadea/vicuna-7b-1.1", api_key="your_api_key")
|
36 |
import requests
|
37 |
|
38 |
API_URL = "https://api-inference.huggingface.co/models/openai-community/gpt2"
|
@@ -73,12 +55,6 @@ def get_grade(similarity_score):
|
|
73 |
else:
|
74 |
return 1
|
75 |
|
76 |
-
def extract_text_from_image(image):
|
77 |
-
# Convert PIL image to RGB format
|
78 |
-
image = image.convert('RGB')
|
79 |
-
# Use pytesseract to extract text from the image
|
80 |
-
text = tess.image_to_string(image)
|
81 |
-
return text.strip()
|
82 |
|
83 |
def evaluate_answer(image):
|
84 |
student_answer = extract_text_from_image(image)
|
@@ -108,7 +84,7 @@ def gradio_interface(image, prompt):
|
|
108 |
|
109 |
interface = gr.Interface(
|
110 |
fn=gradio_interface,
|
111 |
-
inputs=gr.Image(type="
|
112 |
outputs=[gr.Text(label="Grade"), gr.Number(label="Similarity Score (%)"), gr.Text(label="Feedback")],
|
113 |
title="Automated Grading System",
|
114 |
description="Upload an image of your answer sheet to get a grade from 1 to 5, similarity score, and feedback based on the model answer.",
|
|
|
7 |
import pytesseract as tess
|
8 |
from sentence_transformers import SentenceTransformer, util
|
9 |
import io
|
10 |
+
from typing import List
|
11 |
|
12 |
+
def extract_text_from_image(filepath: str, languages: List[str]):
|
13 |
+
image = Image.open(filepath)
|
14 |
+
return pytesseract.image_to_string(image=image, lang=', '.join(languages))
|
15 |
|
16 |
+
# tess.pytesseract.tesseract_cmd = r"tesseract"
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
import requests
|
19 |
|
20 |
API_URL = "https://api-inference.huggingface.co/models/openai-community/gpt2"
|
|
|
55 |
else:
|
56 |
return 1
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
def evaluate_answer(image):
|
60 |
student_answer = extract_text_from_image(image)
|
|
|
84 |
|
85 |
interface = gr.Interface(
|
86 |
fn=gradio_interface,
|
87 |
+
inputs=gr.Image(type="filepath",label="Upload your answer sheet"),
|
88 |
outputs=[gr.Text(label="Grade"), gr.Number(label="Similarity Score (%)"), gr.Text(label="Feedback")],
|
89 |
title="Automated Grading System",
|
90 |
description="Upload an image of your answer sheet to get a grade from 1 to 5, similarity score, and feedback based on the model answer.",
|