Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Load a teaching-capable instruct model
|
| 7 |
+
generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct")
|
| 8 |
+
|
| 9 |
+
# Teacher system prompt
|
| 10 |
+
SYSTEM_PROMPT = """
|
| 11 |
+
You are a professional teacher AI.
|
| 12 |
+
Your job:
|
| 13 |
+
1. Teach the student each lesson in depth, step by step.
|
| 14 |
+
2. After teaching, ask the student 3-5 questions about the lesson.
|
| 15 |
+
3. Evaluate the student’s answers: correct or wrong, with explanations.
|
| 16 |
+
4. If the student struggles, explain again with more clarity and examples.
|
| 17 |
+
5. After mastery, continue to the next lesson.
|
| 18 |
+
|
| 19 |
+
Always stay in Teacher + Tester mode.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
@app.route("/teach", methods=["POST"])
|
| 23 |
+
def teach():
|
| 24 |
+
user_input = request.json.get("message", "")
|
| 25 |
+
full_prompt = SYSTEM_PROMPT + "\n\nStudent: " + user_input + "\nTeacher:"
|
| 26 |
+
|
| 27 |
+
response = generator(full_prompt, max_length=500, do_sample=True, temperature=0.7, top_p=0.9)
|
| 28 |
+
reply = response[0]["generated_text"].split("Teacher:")[-1].strip()
|
| 29 |
+
|
| 30 |
+
return jsonify({"reply": reply})
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
app.run(host="0.0.0.0", port=7860)
|