bluenevus commited on
Commit
82b85b5
·
verified ·
1 Parent(s): a123d64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -1
app.py CHANGED
@@ -46,7 +46,39 @@ if not OPENAI_API_KEY:
46
 
47
  openai.api_key = OPENAI_API_KEY
48
 
49
- # ... (keep all the helper functions as they are) ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  app.layout = dbc.Container([
52
  dbc.Row([
 
46
 
47
  openai.api_key = OPENAI_API_KEY
48
 
49
+ # Add this function definition after the other helper functions and before the app layout
50
+
51
+ def process_media(contents, filename, url):
52
+ logger.info("Starting media processing")
53
+ try:
54
+ if contents:
55
+ content_type, content_string = contents.split(',')
56
+ decoded = base64.b64decode(content_string)
57
+ suffix = os.path.splitext(filename)[1]
58
+ with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as temp_file:
59
+ temp_file.write(decoded)
60
+ temp_file_path = temp_file.name
61
+ logger.info(f"File uploaded: {temp_file_path}")
62
+ elif url:
63
+ temp_file_path = download_media(url)
64
+ else:
65
+ logger.error("No input provided")
66
+ raise ValueError("No input provided")
67
+
68
+ if temp_file_path.lower().endswith(('.mp4', '.avi', '.mov', '.flv', '.wmv')):
69
+ logger.info("Video file detected, extracting audio")
70
+ audio_file_path = extract_audio(temp_file_path)
71
+ transcript = transcribe_audio(audio_file_path)
72
+ os.unlink(audio_file_path)
73
+ else:
74
+ logger.info("Audio file detected, transcribing directly")
75
+ transcript = transcribe_audio(temp_file_path)
76
+
77
+ os.unlink(temp_file_path)
78
+ return transcript
79
+ except Exception as e:
80
+ logger.error(f"Error in process_media: {str(e)}")
81
+ raise
82
 
83
  app.layout = dbc.Container([
84
  dbc.Row([