| | import gradio as gr |
| | from transformers import pipeline |
| |
|
| | |
| | scorer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english") |
| |
|
| | def grade_essay(essay): |
| | if not essay.strip(): |
| | return "⚠️ Please enter an essay text." |
| | |
| | |
| | result = scorer(essay[:512])[0] |
| | score = result['score'] |
| | label = result['label'] |
| |
|
| | |
| | if label == "POSITIVE": |
| | final_score = round(60 + 40 * score, 2) |
| | else: |
| | final_score = round(40 * (1 - score), 2) |
| |
|
| | feedback = f"📊 Sentiment: {label}\n🧾 Estimated Essay Score: {final_score}/100" |
| | return feedback |
| |
|
| | |
| | demo = gr.Interface( |
| | fn=grade_essay, |
| | inputs=gr.Textbox(lines=10, placeholder="Paste your essay here..."), |
| | outputs="text", |
| | title="AI Essay Grader", |
| | description="A simple demo using Hugging Face Transformers to auto-grade essays (simulated).", |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |
| |
|