tejash300 commited on
Commit
631e3bb
·
verified ·
1 Parent(s): 1e18d61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -193,11 +193,12 @@ try:
193
  nlp = spacy.load("en_core_web_sm")
194
  print("✅ Loading NLP models...")
195
 
196
- # Updated summarizer: add trust_remote_code=True to load custom model files if needed.
197
  summarizer = pipeline(
198
  "summarization",
199
  model="nsi319/legal-pegasus",
200
  trust_remote_code=True,
 
201
  device=0 if torch.cuda.is_available() else -1
202
  )
203
  embedding_model = SentenceTransformer("all-mpnet-base-v2", device=device)
@@ -518,7 +519,7 @@ async def analyze_legal_audio(file: UploadFile = File(...)):
518
  temp_file_path = temp_file.name
519
  print(f"Temporary file saved at: {temp_file_path}")
520
  text = process_audio_to_text(temp_file_path)
521
- if os.path.exists(temp_file_path):
522
  os.remove(temp_file_path)
523
  if not text:
524
  return {"status": "error", "message": "No speech could be transcribed from the audio."}
@@ -742,3 +743,4 @@ if __name__ == "__main__":
742
  print("\n⚠️ Ngrok setup failed. API will only be available locally.\n")
743
  run()
744
 
 
 
193
  nlp = spacy.load("en_core_web_sm")
194
  print("✅ Loading NLP models...")
195
 
196
+ # Updated summarizer: add trust_remote_code=True and use_fast=False to avoid Tiktoken conversion errors.
197
  summarizer = pipeline(
198
  "summarization",
199
  model="nsi319/legal-pegasus",
200
  trust_remote_code=True,
201
+ use_fast=False,
202
  device=0 if torch.cuda.is_available() else -1
203
  )
204
  embedding_model = SentenceTransformer("all-mpnet-base-v2", device=device)
 
519
  temp_file_path = temp_file.name
520
  print(f"Temporary file saved at: {temp_file_path}")
521
  text = process_audio_to_text(temp_file_path)
522
+ if os.path.exists(temp_audio_path):
523
  os.remove(temp_file_path)
524
  if not text:
525
  return {"status": "error", "message": "No speech could be transcribed from the audio."}
 
743
  print("\n⚠️ Ngrok setup failed. API will only be available locally.\n")
744
  run()
745
 
746
+