bl4dylion commited on
Commit
3a9a0d8
Β·
1 Parent(s): c2fa877

add auth to the gradio

Browse files
Files changed (2) hide show
  1. .env.template +3 -1
  2. app.py +10 -1
.env.template CHANGED
@@ -1,3 +1,5 @@
1
  OPENAI_API_KEY="..."
2
  11LABS_API_KEY="..."
3
- AIML_API_KEY="..."
 
 
 
1
  OPENAI_API_KEY="..."
2
  11LABS_API_KEY="..."
3
+ AIML_API_KEY="..."
4
+ AUTH_USERS="admin,community_user"
5
+ AUTH_PASS="..."
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  from pathlib import Path
 
3
 
4
  import gradio as gr
5
  from dotenv import load_dotenv
@@ -11,6 +12,14 @@ from src.builder import AudiobookBuilder
11
  from src.config import logger, FILE_SIZE_MAX
12
 
13
 
 
 
 
 
 
 
 
 
14
  def parse_pdf(file_path):
15
  """Parse the PDF file and return the text content."""
16
  loader = PyPDFLoader(file_path)
@@ -112,4 +121,4 @@ with gr.Blocks(title="Audiobooks Generation") as ui:
112
  outputs=error_output,
113
  )
114
 
115
- ui.launch()
 
1
  import os
2
  from pathlib import Path
3
+ from typing import List
4
 
5
  import gradio as gr
6
  from dotenv import load_dotenv
 
12
  from src.config import logger, FILE_SIZE_MAX
13
 
14
 
15
+ def get_auth_params() -> List[tuple[str, str]]:
16
+ users = os.environ["AUTH_USERS"].split(",")
17
+ passwords = os.environ["AUTH_PASS"].split(",")
18
+
19
+ auth_list = [(u, passwords[0] if len(passwords) == 1 else p) for u, p in zip(users, passwords)]
20
+ return auth_list
21
+
22
+
23
  def parse_pdf(file_path):
24
  """Parse the PDF file and return the text content."""
25
  loader = PyPDFLoader(file_path)
 
121
  outputs=error_output,
122
  )
123
 
124
+ ui.launch(auth=get_auth_params())