Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,10 @@
|
|
1 |
-
# Dependencies:
|
2 |
-
# gradio==3.3.1
|
3 |
-
# transformers==4.27.1
|
4 |
-
# torch==2.0.1
|
5 |
-
# pymupdf==1.21.1
|
6 |
-
|
7 |
import gradio as gr
|
8 |
-
|
9 |
import fitz # PyMuPDF
|
|
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
|
14 |
def extract_text_from_pdf(pdf_file):
|
15 |
text = ""
|
@@ -25,7 +20,20 @@ def extract_text_from_pdf(pdf_file):
|
|
25 |
return str(e)
|
26 |
return text
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def evaluate_text_against_rubric(rubric_text, text):
|
|
|
|
|
29 |
# Split rubric into criteria
|
30 |
criteria = [criterion.strip() for criterion in rubric_text.split('\n') if criterion.strip()]
|
31 |
|
@@ -38,7 +46,7 @@ def evaluate_text_against_rubric(rubric_text, text):
|
|
38 |
evaluations = {}
|
39 |
for i, criterion in enumerate(criteria):
|
40 |
try:
|
41 |
-
summary =
|
42 |
evaluations[f'Criteria {i+1}'] = {
|
43 |
"Criterion": criterion,
|
44 |
"Score": 3, # Dummy score for now
|
@@ -53,6 +61,9 @@ def evaluate_text_against_rubric(rubric_text, text):
|
|
53 |
"Example": ""
|
54 |
}
|
55 |
|
|
|
|
|
|
|
56 |
return evaluations
|
57 |
|
58 |
def evaluate(rubric_pdf, rubric_text, text):
|
@@ -90,7 +101,7 @@ with gr.Blocks() as interface:
|
|
90 |
|
91 |
rubric_pdf_input = gr.File(label="Upload Rubric PDF (optional)", type="binary")
|
92 |
rubric_text_input = gr.Textbox(lines=10, placeholder="Or enter your rubric text here...", label="Rubric Text (optional)")
|
93 |
-
text_input = gr.Textbox(lines=10, placeholder="Paste the text to be evaluated here...", label="Text to Evaluate")
|
94 |
|
95 |
evaluate_button = gr.Button("Evaluate")
|
96 |
|
@@ -109,3 +120,4 @@ interface.launch()
|
|
109 |
|
110 |
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
import fitz # PyMuPDF
|
4 |
+
import time
|
5 |
|
6 |
+
# Set your OpenAI API key
|
7 |
+
openai.api_key = 'sk-proj-fCrObs9lnucfEFwJdMkHT3BlbkFJA7auo8szgjDuHz28QGBW'
|
8 |
|
9 |
def extract_text_from_pdf(pdf_file):
|
10 |
text = ""
|
|
|
20 |
return str(e)
|
21 |
return text
|
22 |
|
23 |
+
def generate_summary(text):
|
24 |
+
response = openai.ChatCompletion.create(
|
25 |
+
model="gpt-3.5-turbo",
|
26 |
+
messages=[
|
27 |
+
{"role": "system", "content": "You are a summarization assistant."},
|
28 |
+
{"role": "user", "content": f"Please summarize the following text: {text}"}
|
29 |
+
]
|
30 |
+
)
|
31 |
+
summary = response['choices'][0]['message']['content'].strip()
|
32 |
+
return summary
|
33 |
+
|
34 |
def evaluate_text_against_rubric(rubric_text, text):
|
35 |
+
start_time = time.time()
|
36 |
+
|
37 |
# Split rubric into criteria
|
38 |
criteria = [criterion.strip() for criterion in rubric_text.split('\n') if criterion.strip()]
|
39 |
|
|
|
46 |
evaluations = {}
|
47 |
for i, criterion in enumerate(criteria):
|
48 |
try:
|
49 |
+
summary = generate_summary(text[:1000])
|
50 |
evaluations[f'Criteria {i+1}'] = {
|
51 |
"Criterion": criterion,
|
52 |
"Score": 3, # Dummy score for now
|
|
|
61 |
"Example": ""
|
62 |
}
|
63 |
|
64 |
+
end_time = time.time()
|
65 |
+
print(f"Evaluation took {end_time - start_time} seconds")
|
66 |
+
|
67 |
return evaluations
|
68 |
|
69 |
def evaluate(rubric_pdf, rubric_text, text):
|
|
|
101 |
|
102 |
rubric_pdf_input = gr.File(label="Upload Rubric PDF (optional)", type="binary")
|
103 |
rubric_text_input = gr.Textbox(lines=10, placeholder="Or enter your rubric text here...", label="Rubric Text (optional)")
|
104 |
+
text_input = gr.Textbox(lines=10, placeholder="Paste the text to be evaluated here (max 2000 characters)...", label="Text to Evaluate", max_chars=2000)
|
105 |
|
106 |
evaluate_button = gr.Button("Evaluate")
|
107 |
|
|
|
120 |
|
121 |
|
122 |
|
123 |
+
|