File size: 1,493 Bytes
2e7adc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from langchain.document_loaders.generic import GenericLoader
from langchain.document_loaders.parsers import OpenAIWhisperParser
from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader
import openai
import os
import platform

# Set OpenAI API Key
os.environ['OPENAI_API_KEY'] = "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"
openai.api_key = os.environ['OPENAI_API_KEY']

def add_link(url):
    # Detect the running platform (laptop or mobile)
    running_platform = platform.system().lower()

    # Define saving directory based on the platform
    if running_platform == 'linux' or running_platform == 'darwin':
        save_dir = "docs/youtube/laptop/"
    elif running_platform == 'windows':
        save_dir = "docs/youtube/desktop/"
    else:
        save_dir = "docs/youtube/unknown_platform/"

    # Ensure the directory exists
    os.makedirs(save_dir, exist_ok=True)

    # Create loader and parser
    loader = GenericLoader(
        YoutubeAudioLoader([url], save_dir),
        OpenAIWhisperParser()
    )

    # Load documents
    docs = loader.load()

    # Show a message indicating the downloading process is complete
    completion_message = f"Downloading process for {url} is complete. Saved in {save_dir}"
    return completion_message

# Create Gradio interface
demo = gr.Interface(fn=add_link, inputs='text', outputs='text')

# Launch the interface
if __name__ == "__main__":
    demo.launch(debug=False, share=True)