tejash300 commited on
Commit
b1c7477
Β·
verified Β·
1 Parent(s): 9836bac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -1,23 +1,16 @@
1
- import subprocess
2
- import sys
3
-
4
- # βœ… Force install moviepy before imports
5
- subprocess.run([sys.executable, "-m", "pip", "install", "--no-cache-dir", "moviepy", "imageio[ffmpeg]"])
6
-
7
  import os
8
  import io
9
  import torch
10
  import uvicorn
11
  import spacy
12
  import pdfplumber
13
- import moviepy.editor as mp # Now it will be installed before this line
14
  import librosa
15
  import soundfile as sf
16
  from fastapi import FastAPI, UploadFile, File, HTTPException
17
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
18
  from sentence_transformers import SentenceTransformer, util
19
 
20
-
21
  # βœ… Suppress Warnings
22
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
23
  os.environ['CUDA_VISIBLE_DEVICES'] = '0'
@@ -63,13 +56,12 @@ def extract_text_from_pdf(pdf_file):
63
  except Exception as e:
64
  raise HTTPException(status_code=400, detail=f"PDF extraction failed: {str(e)}")
65
 
66
- # βœ… Video-to-Audio Extraction
67
  def extract_audio_from_video(video_path):
68
- """Extracts audio from a video file."""
69
  try:
70
- video = mp.VideoFileClip(video_path)
71
  audio_path = video_path.replace(".mp4", ".wav")
72
- video.audio.write_audiofile(audio_path, codec="pcm_s16le")
73
  return audio_path
74
  except Exception as e:
75
  raise HTTPException(status_code=500, detail=f"Audio extraction failed: {str(e)}")
@@ -160,3 +152,7 @@ async def analyze_video(file: UploadFile = File(...)):
160
  # βœ… Run FastAPI Server
161
  if __name__ == "__main__":
162
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import io
3
  import torch
4
  import uvicorn
5
  import spacy
6
  import pdfplumber
7
+ import ffmpeg # βœ… Replaced moviepy with ffmpeg-python
8
  import librosa
9
  import soundfile as sf
10
  from fastapi import FastAPI, UploadFile, File, HTTPException
11
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
12
  from sentence_transformers import SentenceTransformer, util
13
 
 
14
  # βœ… Suppress Warnings
15
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
16
  os.environ['CUDA_VISIBLE_DEVICES'] = '0'
 
56
  except Exception as e:
57
  raise HTTPException(status_code=400, detail=f"PDF extraction failed: {str(e)}")
58
 
59
+ # βœ… Video-to-Audio Extraction (Using FFmpeg Instead of MoviePy)
60
  def extract_audio_from_video(video_path):
61
+ """Extracts audio from a video file using FFmpeg."""
62
  try:
 
63
  audio_path = video_path.replace(".mp4", ".wav")
64
+ ffmpeg.input(video_path).output(audio_path, format="wav").run(overwrite_output=True)
65
  return audio_path
66
  except Exception as e:
67
  raise HTTPException(status_code=500, detail=f"Audio extraction failed: {str(e)}")
 
152
  # βœ… Run FastAPI Server
153
  if __name__ == "__main__":
154
  uvicorn.run(app, host="0.0.0.0", port=7860)
155
+
156
+
157
+
158
+