Update app.py
Browse files
app.py
CHANGED
@@ -13,13 +13,17 @@ from dash.exceptions import PreventUpdate
|
|
13 |
import requests
|
14 |
from pytube import YouTube
|
15 |
from pydub import AudioSegment
|
16 |
-
import
|
17 |
|
18 |
# Initialize the Dash app
|
19 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
20 |
|
21 |
-
# Retrieve the
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def is_valid_url(url):
|
25 |
try:
|
@@ -43,8 +47,10 @@ def download_audio(url):
|
|
43 |
|
44 |
def transcribe_audio(file_path):
|
45 |
with open(file_path, "rb") as audio_file:
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
|
49 |
def process_audio(contents, filename, url):
|
50 |
if contents:
|
|
|
13 |
import requests
|
14 |
from pytube import YouTube
|
15 |
from pydub import AudioSegment
|
16 |
+
import google.generativeai as genai
|
17 |
|
18 |
# Initialize the Dash app
|
19 |
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
20 |
|
21 |
+
# Retrieve the Google API key from Hugging Face Spaces
|
22 |
+
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
23 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
24 |
+
|
25 |
+
# Initialize Gemini model
|
26 |
+
model = genai.GenerativeModel('gemini-2.0-flash-lite')
|
27 |
|
28 |
def is_valid_url(url):
|
29 |
try:
|
|
|
47 |
|
48 |
def transcribe_audio(file_path):
|
49 |
with open(file_path, "rb") as audio_file:
|
50 |
+
audio_data = audio_file.read()
|
51 |
+
|
52 |
+
response = model.generate_content(audio_data)
|
53 |
+
return response.text
|
54 |
|
55 |
def process_audio(contents, filename, url):
|
56 |
if contents:
|