Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load a summarization model from Hugging Face
|
5 |
+
summarizer = pipeline("summarization")
|
6 |
+
|
7 |
+
def evaluate_text_against_rubric(rubric, text):
|
8 |
+
# Split rubric into criteria
|
9 |
+
criteria = rubric.split('\n')
|
10 |
+
|
11 |
+
# Use summarizer for each criterion as a dummy placeholder
|
12 |
+
evaluations = {}
|
13 |
+
for i, criterion in enumerate(criteria):
|
14 |
+
if criterion.strip():
|
15 |
+
summary = summarizer(text, max_length=50, min_length=25, do_sample=False)[0]['summary_text']
|
16 |
+
evaluations[f'Criteria {i+1}'] = {
|
17 |
+
"Criterion": criterion,
|
18 |
+
"Score": 3, # Dummy score for now
|
19 |
+
"Comment": f"Evaluation based on criterion: {criterion}",
|
20 |
+
"Example": summary
|
21 |
+
}
|
22 |
+
return evaluations
|
23 |
+
|
24 |
+
def evaluate(rubric, text):
|
25 |
+
evaluation = evaluate_text_against_rubric(rubric, text)
|
26 |
+
evaluation_text = ""
|
27 |
+
for criterion, details in evaluation.items():
|
28 |
+
evaluation_text += f"{criterion}:\n"
|
29 |
+
evaluation_text += f" Criterion: {details['Criterion']}\n"
|
30 |
+
evaluation_text += f" Score: {details['Score']}\n"
|
31 |
+
evaluation_text += f" Comment: {details['Comment']}\n"
|
32 |
+
evaluation_text += f" Example: {details['Example']}\n\n"
|
33 |
+
return evaluation_text
|
34 |
+
|
35 |
+
# Create Gradio interface
|
36 |
+
interface = gr.Interface(
|
37 |
+
fn=evaluate,
|
38 |
+
inputs=[
|
39 |
+
gr.Textbox(lines=10, placeholder="Enter your rubric here..."),
|
40 |
+
gr.Textbox(lines=10, placeholder="Paste the text to be evaluated here...")
|
41 |
+
],
|
42 |
+
outputs="text",
|
43 |
+
title="Text Evaluator",
|
44 |
+
description="Upload or enter a rubric and paste text for evaluation. The system will grade the text against the rubric and provide feedback."
|
45 |
+
)
|
46 |
+
|
47 |
+
# Launch the interface
|
48 |
+
interface.launch()
|