Spaces:
Sleeping
Sleeping
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from langchain.document_loaders.generic import GenericLoader
|
3 |
+
from langchain.document_loaders.parsers import OpenAIWhisperParser
|
4 |
+
from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
|
5 |
+
import openai
|
6 |
+
import os
|
7 |
+
import platform
|
8 |
+
|
9 |
+
# Set OpenAI API Key
|
10 |
+
os.environ['OPENAI_API_KEY'] = "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"
|
11 |
+
openai.api_key = os.environ['OPENAI_API_KEY']
|
12 |
+
|
13 |
+
def add_link(url):
|
14 |
+
# Detect the running platform (laptop or mobile)
|
15 |
+
running_platform = platform.system().lower()
|
16 |
+
|
17 |
+
# Define saving directory based on the platform
|
18 |
+
if running_platform == 'linux' or running_platform == 'darwin':
|
19 |
+
save_dir = "docs/youtube/laptop/"
|
20 |
+
elif running_platform == 'windows':
|
21 |
+
save_dir = "docs/youtube/desktop/"
|
22 |
+
else:
|
23 |
+
save_dir = "docs/youtube/unknown_platform/"
|
24 |
+
|
25 |
+
# Ensure the directory exists
|
26 |
+
os.makedirs(save_dir, exist_ok=True)
|
27 |
+
|
28 |
+
# Create loader and parser
|
29 |
+
loader = GenericLoader(
|
30 |
+
YoutubeAudioLoader([url], save_dir),
|
31 |
+
OpenAIWhisperParser()
|
32 |
+
)
|
33 |
+
|
34 |
+
# Load documents
|
35 |
+
docs = loader.load()
|
36 |
+
|
37 |
+
# Show a message indicating the downloading process is complete
|
38 |
+
completion_message = f"Downloading process for {url} is complete. Saved in {save_dir}"
|
39 |
+
return completion_message
|
40 |
+
|
41 |
+
# Create Gradio interface
|
42 |
+
demo = gr.Interface(fn=add_link, inputs='text', outputs='text')
|
43 |
+
|
44 |
+
# Launch the interface
|
45 |
+
if __name__ == "__main__":
|
46 |
+
demo.launch(debug=False, share=True)
|