mike23415 commited on
Commit
3b4df89
·
verified ·
1 Parent(s): 9fd7d89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  from transformers import pipeline
3
 
4
  # Ensure HF doesn't request a token
@@ -10,8 +11,25 @@ os.environ["HF_HUB_OFFLINE"] = "0"
10
  # Load model
11
  summarizer = pipeline("summarization", model="t5-base")
12
 
13
- # Ensure script runs properly
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if __name__ == "__main__":
15
- print("Application started successfully!")
16
- result = summarizer("This is a long text that needs summarization.", max_length=50, min_length=10, do_sample=False)
17
- print(result)
 
1
  import os
2
+ from flask import Flask, request, jsonify
3
  from transformers import pipeline
4
 
5
  # Ensure HF doesn't request a token
 
11
  # Load model
12
  summarizer = pipeline("summarization", model="t5-base")
13
 
14
+ app = Flask(__name__)
15
+
16
+ @app.route("/")
17
+ def home():
18
+ return "Summarization API is running!"
19
+
20
+ @app.route("/summarize", methods=["POST"])
21
+ def summarize_text():
22
+ data = request.get_json()
23
+ text = data.get("text", "")
24
+ max_length = data.get("max_length", 50)
25
+ min_length = data.get("min_length", 10)
26
+
27
+ if not text:
28
+ return jsonify({"error": "No text provided"}), 400
29
+
30
+ summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=False)
31
+ return jsonify(summary)
32
+
33
  if __name__ == "__main__":
34
+ print("🚀 API is running on port 7860")
35
+ app.run(host="0.0.0.0", port=7860)