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