Cheongwoon commited on
Commit
d5c0829
ยท
verified ยท
1 Parent(s): 0e338e6

Create econ_analyzer

Browse files
Files changed (1) hide show
  1. 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)