AhsanShahid commited on
Commit
596c1a0
·
verified ·
1 Parent(s): f310226

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -20
app.py CHANGED
@@ -1,29 +1,21 @@
1
- # prompt: give me inference of my code
 
2
 
3
- # Assuming 'model_path' is the path to your saved model
4
- model_path = '/content/drive/MyDrive/ahsan'
5
 
6
  # Load the fine-tuned model and tokenizer
 
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
8
  tokenizer = AutoTokenizer.from_pretrained(model_path)
9
 
10
  summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
11
 
12
- # Input text for summarization
13
- input_text = """
 
 
 
 
14
 
15
- The logjam coincided with the Bohra community leader’s arrival at the Sindh Governor House.
16
-
17
- In an alert posted at 7:38pm, the Karachi Traffic Police s aid Ziauddin Ahmed road going towards PIDC Chowk to the State Life Building was opened for one-track traffic coming and going.
18
-
19
- Sindh Chief Minister Murad Ali Shah took notice of the traffic situation and ordered the administration, district and traffic police to open roads for traffic.
20
-
21
- He also instructed that traffic management in the city be improved and further directed that the CM Secretariat be reported to after the opening of roads.
22
-
23
-
24
- """
25
- # Perform summarization
26
- summary = summarizer(input_text, max_length=50, min_length=20, length_penalty=2.0)
27
-
28
- # Print the generated summary
29
- print("Summary:", summary[0]['summary_text'])
 
1
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
2
+ from flask import Flask, request, jsonify
3
 
4
+ app = Flask(__name__)
 
5
 
6
  # Load the fine-tuned model and tokenizer
7
+ model_path = '/content/drive/MyDrive/ahsan' # Replace with the path to your model
8
  model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
9
  tokenizer = AutoTokenizer.from_pretrained(model_path)
10
 
11
  summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
12
 
13
+ @app.route('/summarize', methods=['POST'])
14
+ def summarize():
15
+ data = request.json
16
+ input_text = data.get('text', '')
17
+ summary = summarizer(input_text, max_length=50, min_length=20, length_penalty=2.0)
18
+ return jsonify({"summary": summary[0]['summary_text']})
19
 
20
+ if __name__ == '__main__':
21
+ app.run(host='0.0.0.0', port=5000)