iukea/open-notebooklm
0
1"""2constants.py3"""4 5import os6 7from pathlib import Path8 9# Key constants10APP_TITLE = "Open NotebookLM"11CHARACTER_LIMIT = 100_00012 13# Gradio-related constants14GRADIO_CACHE_DIR = "./gradio_cached_examples/tmp/"15GRADIO_CLEAR_CACHE_OLDER_THAN = 1 * 24 * 60 * 60 # 1 day16 17# Error messages-related constants18ERROR_MESSAGE_NO_INPUT = "Please provide at least one PDF file or a URL."19ERROR_MESSAGE_NOT_PDF = "The provided file is not a PDF. Please upload only PDF files."20ERROR_MESSAGE_NOT_SUPPORTED_IN_MELO_TTS = "The selected language is not supported without advanced audio generation. Please enable advanced audio generation or choose a supported language."21ERROR_MESSAGE_READING_PDF = "Error reading the PDF file"22ERROR_MESSAGE_TOO_LONG = "The total content is too long. Please ensure the combined text from PDFs and URL is fewer than {CHARACTER_LIMIT} characters."23 24# Fireworks API-related constants25FIREWORKS_API_KEY = os.getenv("FIREWORKS_API_KEY")26FIREWORKS_BASE_URL = "https://api.fireworks.ai/inference/v1"27FIREWORKS_MAX_TOKENS = 16_38428FIREWORKS_MODEL_ID = "accounts/fireworks/models/llama-v3p1-405b-instruct"29FIREWORKS_TEMPERATURE = 0.130FIREWORKS_JSON_RETRY_ATTEMPTS = 331 32# MeloTTS33MELO_API_NAME = "/synthesize"34MELO_TTS_SPACES_ID = "mrfakename/MeloTTS"35MELO_RETRY_ATTEMPTS = 336MELO_RETRY_DELAY = 5 # in seconds37 38MELO_TTS_LANGUAGE_MAPPING = {39 "en": "EN",40 "es": "ES",41 "fr": "FR",42 "zh": "ZJ",43 "ja": "JP",44 "ko": "KR",45}46 47 48# Suno related constants49SUNO_LANGUAGE_MAPPING = {50 "English": "en",51 "Chinese": "zh",52 "French": "fr",53 "German": "de",54 "Hindi": "hi",55 "Italian": "it",56 "Japanese": "ja",57 "Korean": "ko",58 "Polish": "pl",59 "Portuguese": "pt",60 "Russian": "ru",61 "Spanish": "es",62 "Turkish": "tr",63}64 65# General audio-related constants66NOT_SUPPORTED_IN_MELO_TTS = list(67 set(SUNO_LANGUAGE_MAPPING.values()) - set(MELO_TTS_LANGUAGE_MAPPING.keys())68)69NOT_SUPPORTED_IN_MELO_TTS = [70 key for key, id in SUNO_LANGUAGE_MAPPING.items() if id in NOT_SUPPORTED_IN_MELO_TTS71]72 73# Jina Reader-related constants74JINA_READER_URL = "https://r.jina.ai/"75JINA_RETRY_ATTEMPTS = 376JINA_RETRY_DELAY = 5 # in seconds77 78# UI-related constants79UI_DESCRIPTION = """80<table style="border-collapse: collapse; border: none; padding: 20px;">81 <tr style="border: none;">82 <td style="border: none; vertical-align: top; padding-right: 30px; padding-left: 30px;">83 <img src="https://raw.githubusercontent.com/gabrielchua/daily-ai-papers/main/_includes/icon.png" alt="Open NotebookLM" width="120" style="margin-bottom: 10px;">84 </td>85 <td style="border: none; vertical-align: top; padding: 10px;">86 <p style="margin-bottom: 15px;">Convert your PDFs into podcasts with open-source AI models (<a href="https://huggingface.co/meta-llama/Llama-3.1-405B">Llama 3.1 405B</a>, <a href="https://huggingface.co/myshell-ai/MeloTTS-English">MeloTTS</a>, <a href="https://huggingface.co/suno/bark">Bark</a>).</p>87 <p style="margin-top: 15px;">Note: Only the text content of the PDFs will be processed. Images and tables are not included. The total content should be no more than 100,000 characters due to the context length of Llama 3.1 405B.</p>88 </td>89 </tr>90</table>91"""92UI_AVAILABLE_LANGUAGES = list(set(SUNO_LANGUAGE_MAPPING.keys()))93UI_INPUTS = {94 "file_upload": {95 "label": "1. ๐ Upload your PDF(s)",96 "file_types": [".pdf"],97 "file_count": "multiple",98 },99 "url": {100 "label": "2. ๐ Paste a URL (optional)",101 "placeholder": "Enter a URL to include its content",102 },103 "question": {104 "label": "3. ๐ค Do you have a specific question or topic in mind?",105 "placeholder": "Enter a question or topic",106 },107 "tone": {108 "label": "4. ๐ญ Choose the tone",109 "choices": ["Fun", "Formal"],110 "value": "Fun",111 },112 "length": {113 "label": "5. โฑ๏ธ Choose the length",114 "choices": ["Short (1-2 min)", "Medium (3-5 min)"],115 "value": "Medium (3-5 min)",116 },117 "language": {118 "label": "6. ๐ Choose the language",119 "choices": UI_AVAILABLE_LANGUAGES,120 "value": "English",121 },122 "advanced_audio": {123 "label": "7. ๐ Use advanced audio generation? (Experimental)",124 "value": False,125 },126}127UI_OUTPUTS = {128 "audio": {"label": "๐ Podcast", "format": "mp3"},129 "transcript": {130 "label": "๐ Transcript",131 },132}133UI_API_NAME = "generate_podcast"134UI_ALLOW_FLAGGING = "never"135UI_CONCURRENCY_LIMIT = 3136UI_EXAMPLES = [137 [138 [str(Path("examples/1310.4546v1.pdf"))],139 "",140 "Explain this paper to me like I'm 5 years old",141 "Fun",142 "Short (1-2 min)",143 "English",144 True,145 ],146 [147 [],148 "https://en.wikipedia.org/wiki/Hugging_Face",149 "How did Hugging Face become so successful?",150 "Fun",151 "Short (1-2 min)",152 "English",153 False,154 ],155 [156 [],157 "https://simple.wikipedia.org/wiki/Taylor_Swift",158 "Why is Taylor Swift so popular?",159 "Fun",160 "Short (1-2 min)",161 "English",162 False,163 ],164]165UI_CACHE_EXAMPLES = True166UI_SHOW_API = True167 