Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,50 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
Return the following checklist JSON with clear Yes/No and 0-3 scores.
|
| 11 |
-
|
| 12 |
-
Checklist:
|
| 13 |
-
{{
|
| 14 |
-
"G1": "", "G2": "", "G3": "", "G4": "", "G5": "",
|
| 15 |
-
"S1": 0, "S2": 0, "S3": 0, "S4": 0, "S5": 0,
|
| 16 |
-
"comments": ""
|
| 17 |
-
}}
|
| 18 |
-
|
| 19 |
-
Problem statement: \"\"\"{problem_statement}\"\"\"
|
| 20 |
-
|
| 21 |
-
Checklist:
|
| 22 |
"""
|
| 23 |
-
result = generator(prompt)[0]["generated_text"]
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
# Evaluate decision logic (simple heuristic)
|
| 30 |
try:
|
| 31 |
-
checklist =
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
else:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
decision = "✅ Meets requirements (Proficient)"
|
| 40 |
-
else:
|
| 41 |
-
decision = "⚠️ Needs Improvement"
|
| 42 |
-
except:
|
| 43 |
-
decision = "⚠️ Could not evaluate due to JSON parsing error."
|
| 44 |
-
|
| 45 |
-
return checklist_json, decision
|
| 46 |
|
| 47 |
iface = gr.Interface(
|
| 48 |
-
fn=
|
| 49 |
-
inputs=gr.Textbox(label="
|
| 50 |
-
outputs=[
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
],
|
| 54 |
-
title="🧠 REU Research Problem Evaluator",
|
| 55 |
-
description="Paste a research problem statement. The evaluator will fill the feasibility checklist and recommend action."
|
| 56 |
)
|
| 57 |
-
|
| 58 |
iface.launch()
|
|
|
|
| 1 |
+
import os, json, gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
MODEL_ID = "tiiuae/falcon-7b-instruct" # keep the big model
|
| 5 |
+
client = InferenceClient(model=MODEL_ID, token=os.getenv("HF_TOKEN"))
|
| 6 |
|
| 7 |
+
SYSTEM_PROMPT = """You are an evaluator of undergraduate research problem statements.
|
| 8 |
+
Return only a JSON object with the following keys:
|
| 9 |
+
G1,G2,G3,G4,G5 (Yes/No) and S1–S5 (0-3) and comments.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
|
|
|
| 11 |
|
| 12 |
+
def assess(statement):
|
| 13 |
+
prompt = f"{SYSTEM_PROMPT}\nProblem statement:\n\"\"\"{statement}\"\"\"\nChecklist:"
|
| 14 |
+
response = client.text_generation(
|
| 15 |
+
prompt,
|
| 16 |
+
max_new_tokens=256,
|
| 17 |
+
temperature=0.1,
|
| 18 |
+
top_p=0.9,
|
| 19 |
+
stream=False,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Get first JSON block
|
| 23 |
+
start = response.find("{")
|
| 24 |
+
end = response.rfind("}") + 1
|
| 25 |
+
json_str = response[start:end] if start != -1 else "{}"
|
| 26 |
|
|
|
|
| 27 |
try:
|
| 28 |
+
checklist = json.loads(json_str)
|
| 29 |
+
gate_fail = any(checklist.get(f"G{i}") == "No" for i in range(1,6))
|
| 30 |
+
score = sum(int(checklist.get(f"S{i}",0)) for i in range(1,6))
|
| 31 |
+
if gate_fail:
|
| 32 |
+
verdict = "❌ Mandatory gatekeeper criterion failed."
|
| 33 |
+
elif score >= 11:
|
| 34 |
+
verdict = "✅ Meets requirements (Exceptional/Proficient)."
|
| 35 |
+
elif score >= 8:
|
| 36 |
+
verdict = "⚠️ Adequate but needs refinement."
|
| 37 |
else:
|
| 38 |
+
verdict = "❌ Needs major improvement."
|
| 39 |
+
except Exception as e:
|
| 40 |
+
verdict = f"⚠️ JSON parse error: {e}"
|
| 41 |
+
return json_str, verdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
iface = gr.Interface(
|
| 44 |
+
fn=assess,
|
| 45 |
+
inputs=gr.Textbox(lines=8, label="Paste REU Problem Statement"),
|
| 46 |
+
outputs=[gr.Code(label="Checklist JSON"), gr.Textbox(label="Verdict")],
|
| 47 |
+
title="🧠 REU Problem Statement Evaluator",
|
| 48 |
+
description="Uses the Hugging Face Inference API so no large model is loaded in the Space itself."
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
|
|
|
| 50 |
iface.launch()
|