memorease commited on
Commit
c951e9f
·
verified ·
1 Parent(s): cb64e4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -1,15 +1,11 @@
1
  from flask import Flask, request, jsonify
2
  from gradio_client import Client
3
  import os
 
4
 
5
  app = Flask(__name__)
6
 
7
- try:
8
- print(">>> INITIALIZING CLIENT...")
9
- client = Client("memorease/memorease-flan-t5")
10
- except Exception as e:
11
- print(">>> CLIENT INIT ERROR:", str(e))
12
- client = None # fallback
13
 
14
  @app.route("/ask", methods=["POST"])
15
  def ask_question():
@@ -20,13 +16,9 @@ def ask_question():
20
  if not input_text:
21
  return jsonify({"error": "Missing 'text'"}), 400
22
 
23
- if client is None:
24
- return jsonify({"error": "Model client failed to initialize."}), 500
25
-
26
- result = client.predict(input_text, api_name="/predict")
27
-
28
  print("RESULT:", result)
29
- return jsonify({"question": result})
30
  except Exception as e:
31
  print("SERVER ERROR:", str(e))
32
  return jsonify({"error": str(e)}), 500
 
1
  from flask import Flask, request, jsonify
2
  from gradio_client import Client
3
  import os
4
+ from transformers import pipeline
5
 
6
  app = Flask(__name__)
7
 
8
+ question_generator = pipeline("text2text-generation", model="memorease/memorease-flan-t5")
 
 
 
 
 
9
 
10
  @app.route("/ask", methods=["POST"])
11
  def ask_question():
 
16
  if not input_text:
17
  return jsonify({"error": "Missing 'text'"}), 400
18
 
19
+ result = question_generator(f"Generate a question from this sentence: {input_text}")
 
 
 
 
20
  print("RESULT:", result)
21
+ return jsonify({"question": result[0]["generated_text"]})
22
  except Exception as e:
23
  print("SERVER ERROR:", str(e))
24
  return jsonify({"error": str(e)}), 500