Spaces:
Build error
Build error
Create econ_analyzer
Browse files- econ_analyzer +37 -0
econ_analyzer
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# โ
๊ฒฝ์ ํด์ ๋ชจ๋ธ: ๋ถ์๊ธฐ (analyzer)
|
| 7 |
+
econ_analyzer = pipeline(
|
| 8 |
+
"summarization", # ๐คซ ์ฌ์ค์ ์์ฝ ํ์ดํ๋ผ์ธ์ ํ์ฉํ โํด์ ์์ฑ๊ธฐโ ์ญํ
|
| 9 |
+
model="digit82/kobart-summarization",
|
| 10 |
+
tokenizer="digit82/kobart-summarization"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
@app.route("/")
|
| 14 |
+
def home():
|
| 15 |
+
return "๐ CW ๊ฒฝ์ ๋ถ์๊ธฐ (KoBART ๊ธฐ๋ฐ) ๋์ ์ค"
|
| 16 |
+
|
| 17 |
+
@app.route("/econalyze", methods=["POST"])
|
| 18 |
+
def analyze_economy():
|
| 19 |
+
data = request.get_json()
|
| 20 |
+
econ_input = data.get("text", "")
|
| 21 |
+
|
| 22 |
+
if not econ_input.strip():
|
| 23 |
+
return jsonify({"error": "๊ฒฝ์ ์งํ ์
๋ ฅ์ด ์์ต๋๋ค"}), 400
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
result = econ_analyzer(
|
| 27 |
+
econ_input,
|
| 28 |
+
max_length=300,
|
| 29 |
+
min_length=80,
|
| 30 |
+
do_sample=False
|
| 31 |
+
)
|
| 32 |
+
return jsonify({"analysis": result[0]["summary_text"]})
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return jsonify({"error": str(e)}), 500
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
app.run(host="0.0.0.0", port=7861)
|