Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
from flask import Flask, request, jsonify
|
4 |
+
from hf_integration import HuggingFaceIntegration
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
import os
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
app = Flask(__name__)
|
11 |
+
hf = HuggingFaceIntegration()
|
12 |
+
|
13 |
+
# Example of a protected route
|
14 |
+
@app.route('/generate-questions', methods=['POST'])
|
15 |
+
def generate_questions():
|
16 |
+
data = request.json
|
17 |
+
subject = data.get('subject', 'english')
|
18 |
+
difficulty = data.get('difficulty', 'medium')
|
19 |
+
|
20 |
+
result = hf.generate_questions(subject, difficulty)
|
21 |
+
return jsonify(result)
|
22 |
+
|
23 |
+
@app.route('/evaluate-writing', methods=['POST'])
|
24 |
+
def evaluate_writing():
|
25 |
+
text = request.json.get('text')
|
26 |
+
if not text:
|
27 |
+
return jsonify({"error": "No text provided"}), 400
|
28 |
+
|
29 |
+
result = hf.evaluate_writing(text)
|
30 |
+
return jsonify(result)
|
31 |
+
|
32 |
+
if __name__ == '__main__':
|
33 |
+
app.run(host='0.0.0.0', port=5000, debug=True)
|