memorease commited on
Commit
b446f4f
·
verified ·
1 Parent(s): 8fdfdf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,24 +1,21 @@
1
  from flask import Flask, request, jsonify
2
- from transformers import pipeline
3
  import os
4
 
5
  app = Flask(__name__)
6
 
7
- pipe = pipeline("text2text-generation", model="memorease/flan5_memorease", token=os.environ.get("HF_TOKEN"))
8
-
9
  @app.route("/ask", methods=["POST"])
10
  def ask_question():
11
  try:
 
12
  input_text = request.json.get("text")
13
- result = pipe(f"Generate a question about: {input_text}")[0]["generated_text"]
 
 
14
  return jsonify({"question": result})
15
  except Exception as e:
16
  return jsonify({"error": str(e)}), 500
17
 
18
- @app.route("/", methods=["GET"])
19
- def root_check():
20
- return jsonify({"status": "running"})
21
-
22
  if __name__ == "__main__":
23
  port = int(os.environ.get("PORT", 7860))
24
  app.run(host="0.0.0.0", port=port)
 
1
  from flask import Flask, request, jsonify
2
+ from gradio_client import Client
3
  import os
4
 
5
  app = Flask(__name__)
6
 
 
 
7
  @app.route("/ask", methods=["POST"])
8
  def ask_question():
9
  try:
10
+ client = Client("memorease/flan5_memorease")
11
  input_text = request.json.get("text")
12
+ if not input_text:
13
+ return jsonify({"error": "Missing 'text'"}), 400
14
+ result = client.predict(input_text, api_name="/predict")
15
  return jsonify({"question": result})
16
  except Exception as e:
17
  return jsonify({"error": str(e)}), 500
18
 
 
 
 
 
19
  if __name__ == "__main__":
20
  port = int(os.environ.get("PORT", 7860))
21
  app.run(host="0.0.0.0", port=port)