maahi2412 commited on
Commit
0013019
·
verified ·
1 Parent(s): cc0c049

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -13,18 +13,18 @@ from sklearn.feature_extraction.text import TfidfVectorizer
13
  from sklearn.metrics.pairwise import cosine_similarity
14
 
15
  app = Flask(__name__)
16
- CORS(app) # Enable CORS for frontend compatibility
17
  UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
18
  PEGASUS_MODEL_DIR = 'fine_tuned_pegasus'
19
  BERT_MODEL_DIR = 'fine_tuned_bert'
20
  LEGALBERT_MODEL_DIR = 'fine_tuned_legalbert'
21
- MAX_FILE_SIZE = 100 * 1024 * 1024 # 100 MB limit
22
 
23
  # Ensure upload folder exists
24
  if not os.path.exists(UPLOAD_FOLDER):
25
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
26
 
27
- transformers.logging.set_verbosity_error() # Suppress transformers warnings
28
  os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
29
 
30
  # Pegasus Fine-Tuning
@@ -39,7 +39,7 @@ def load_or_finetune_pegasus():
39
  model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
40
 
41
  cnn_dm = load_dataset("cnn_dailymail", "3.0.0", split="train[:5000]")
42
- xsum = load_dataset("xsum", split="train[:5000]")
43
  combined_dataset = concatenate_datasets([cnn_dm, xsum])
44
 
45
  def preprocess_function(examples):
@@ -319,5 +319,5 @@ def summarize_document():
319
  return jsonify({"model_used": model, "summary": summary})
320
 
321
  if __name__ == '__main__':
322
- port = int(os.environ.get("PORT", 5000)) # Use PORT env var if set by Hugging Face
323
  app.run(debug=False, host='0.0.0.0', port=port)
 
13
  from sklearn.metrics.pairwise import cosine_similarity
14
 
15
  app = Flask(__name__)
16
+ CORS(app)
17
  UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads')
18
  PEGASUS_MODEL_DIR = 'fine_tuned_pegasus'
19
  BERT_MODEL_DIR = 'fine_tuned_bert'
20
  LEGALBERT_MODEL_DIR = 'fine_tuned_legalbert'
21
+ MAX_FILE_SIZE = 100 * 1024 * 1024
22
 
23
  # Ensure upload folder exists
24
  if not os.path.exists(UPLOAD_FOLDER):
25
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
26
 
27
+ transformers.logging.set_verbosity_error()
28
  os.environ["HF_HUB_DISABLE_SYMLINKS_WARNING"] = "1"
29
 
30
  # Pegasus Fine-Tuning
 
39
  model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
40
 
41
  cnn_dm = load_dataset("cnn_dailymail", "3.0.0", split="train[:5000]")
42
+ xsum = load_dataset("xsum", split="train[:5000]", trust_remote_code=True) # Added trust_remote_code=True
43
  combined_dataset = concatenate_datasets([cnn_dm, xsum])
44
 
45
  def preprocess_function(examples):
 
319
  return jsonify({"model_used": model, "summary": summary})
320
 
321
  if __name__ == '__main__':
322
+ port = int(os.environ.get("PORT", 5000))
323
  app.run(debug=False, host='0.0.0.0', port=port)