Shridhartd commited on
Commit
ce7ae74
·
verified ·
1 Parent(s): 25aeb58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -47
app.py CHANGED
@@ -1,58 +1,50 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load a Hugging Face instruction-tuned model
5
- generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_new_tokens=256)
6
 
7
- def evaluate_reu_problem(problem_statement):
8
- prompt = f"""
9
- You are an evaluator of undergraduate research problem statements.
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
- # Extract only JSON (if possible)
26
- json_start = result.find("{")
27
- checklist_json = result[json_start:].strip() if json_start != -1 else "Unable to parse JSON."
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- # Evaluate decision logic (simple heuristic)
30
  try:
31
- checklist = eval(checklist_json)
32
- if any(checklist.get(f"G{i}", "No") == "No" for i in range(1, 6)):
33
- decision = " Does NOT meet requirements. Please revise the problem statement."
 
 
 
 
 
 
34
  else:
35
- score = sum(checklist.get(f"S{i}", 0) for i in range(1, 6))
36
- if score >= 11:
37
- decision = " Meets requirements (Exceptional)"
38
- elif score >= 8:
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=evaluate_reu_problem,
49
- inputs=gr.Textbox(label="Enter REU Problem Statement", lines=7),
50
- outputs=[
51
- gr.Textbox(label="Checklist (JSON Output)", lines=15),
52
- gr.Textbox(label="Final Assessment")
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()