Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,38 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
app = Flask(
|
| 5 |
-
|
| 6 |
-
β
KoBART μμ½κΈ° κ³΅ν΅ μ¬μ©
|
| 7 |
|
|
|
|
| 8 |
summarizer = pipeline("summarization", model="digit82/kobart-summarization", tokenizer="digit82/kobart-summarization")
|
| 9 |
|
| 10 |
@app.route("/")
|
| 11 |
def home():
|
| 12 |
-
return "
|
| 13 |
|
| 14 |
@app.route("/summarize", methods=["POST"])
|
| 15 |
def summarize():
|
| 16 |
-
data = request.get_json()
|
| 17 |
-
text = data.get("text", "")
|
| 18 |
-
if not text.strip():
|
| 19 |
-
return jsonify({"error": "μμ½ν ν
μ€νΈκ° μμ΅λλ€"}), 400
|
| 20 |
-
try:
|
| 21 |
-
result = summarizer(text, max_length=200, min_length=40, do_sample=False)
|
| 22 |
-
return jsonify({"summary": result[0]["summary_text"]})
|
| 23 |
-
except Exception as e:
|
| 24 |
-
return jsonify({"error": str(e)}), 500
|
| 25 |
|
| 26 |
@app.route("/econalyze", methods=["POST"])
|
| 27 |
-
def
|
| 28 |
-
data = request.get_json()
|
| 29 |
-
|
| 30 |
-
if not
|
| 31 |
-
return jsonify({"error": "κ²½μ
|
| 32 |
-
try:
|
| 33 |
-
result = summarizer(
|
| 34 |
-
return jsonify({"analysis": result[0]["summary_text"]})
|
| 35 |
-
except Exception as e:
|
| 36 |
-
return jsonify({"error": str(e)}), 500
|
| 37 |
|
| 38 |
-
if
|
| 39 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# KoBART μμ½κΈ° κ³΅ν΅ μ¬μ©
|
| 7 |
summarizer = pipeline("summarization", model="digit82/kobart-summarization", tokenizer="digit82/kobart-summarization")
|
| 8 |
|
| 9 |
@app.route("/")
|
| 10 |
def home():
|
| 11 |
+
return "CW KoBART μμ½ μλ² μλ μ€ (λ©ν° μλν¬μΈνΈ /summarize, /econalyze)"
|
| 12 |
|
| 13 |
@app.route("/summarize", methods=["POST"])
|
| 14 |
def summarize():
|
| 15 |
+
data = request.get_json()
|
| 16 |
+
text = data.get("text", "")
|
| 17 |
+
if not text.strip():
|
| 18 |
+
return jsonify({"error": "μμ½ν ν
μ€νΈκ° μμ΅λλ€"}), 400
|
| 19 |
+
try:
|
| 20 |
+
result = summarizer(text, max_length=200, min_length=40, do_sample=False)
|
| 21 |
+
return jsonify({"summary": result[0]["summary_text"]})
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return jsonify({"error": str(e)}), 500
|
| 24 |
|
| 25 |
@app.route("/econalyze", methods=["POST"])
|
| 26 |
+
def econalyze():
|
| 27 |
+
data = request.get_json()
|
| 28 |
+
text = data.get("text", "")
|
| 29 |
+
if not text.strip():
|
| 30 |
+
return jsonify({"error": "κ²½μ λΆμ μ
λ ₯μ΄ μμ΅λλ€"}), 400
|
| 31 |
+
try:
|
| 32 |
+
result = summarizer(text, max_length=300, min_length=80, do_sample=False)
|
| 33 |
+
return jsonify({"analysis": result[0]["summary_text"]})
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return jsonify({"error": str(e)}), 500
|
| 36 |
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
app.run(host="0.0.0.0", port=7860)
|