Hitakshi26 commited on
Commit
7045d49
·
1 Parent(s): b0d1e07

Fix HF runtime

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. src/frontend/ui.py +272 -31
app.py CHANGED
@@ -1,6 +1,11 @@
 
1
  from src.frontend.ui import build_app
2
 
3
  demo = build_app()
4
 
5
  if __name__ == "__main__":
6
- demo.launch()
 
 
 
 
 
1
+ import os
2
  from src.frontend.ui import build_app
3
 
4
  demo = build_app()
5
 
6
  if __name__ == "__main__":
7
+ demo.queue().launch(
8
+ server_name="0.0.0.0",
9
+ server_port=int(os.getenv("PORT", "7860")),
10
+ show_api=False,
11
+ )
src/frontend/ui.py CHANGED
@@ -1,80 +1,321 @@
1
  import gradio as gr
2
  from src.frontend.callbacks import (
3
- ui_bootstrap, on_switch_notebook, on_create_notebook, on_rename_notebook, on_delete_notebook,
4
- on_ingest_files, on_ingest_url, on_chat, on_report, on_quiz, on_podcast, on_download
 
 
 
 
 
 
 
 
 
 
5
  )
6
  from src.backend.auth import require_login
7
 
 
8
  def build_app():
 
9
  with gr.Blocks(title="NotebookLM Clone") as demo:
 
10
  gr.Markdown("# 📓 NotebookLM Clone (HF Auth + Chroma + RAG)")
11
 
12
  login = gr.LoginButton()
 
13
  username_state = gr.State("")
14
 
 
15
  def on_load(request: gr.Request):
16
  username = require_login(request)
17
  dd, chat, arts = ui_bootstrap(username)
18
  return username, dd, chat, arts
19
 
20
  with gr.Row():
 
 
21
  with gr.Column(scale=1):
22
- user_box = gr.Textbox(label="User", interactive=False)
23
- notebook_dd = gr.Dropdown(label="Notebooks", choices=[], interactive=True)
24
 
25
- nb_new = gr.Textbox(label="Create notebook", placeholder="Name")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  btn_create = gr.Button("Create")
27
 
28
- nb_rename = gr.Textbox(label="Rename notebook", placeholder="New name")
 
 
 
 
29
  btn_rename = gr.Button("Rename")
30
 
31
- btn_delete = gr.Button("Delete current", variant="stop")
 
 
 
32
 
 
33
  gr.Markdown("## Ingest")
34
- file_up = gr.File(label="Upload PDF/PPTX/TXT", file_count="multiple")
 
 
 
 
 
35
  btn_ingest_files = gr.Button("Ingest Files")
36
- ingest_status = gr.Textbox(label="Status", interactive=False)
37
 
38
- url_in = gr.Textbox(label="URL", placeholder="https://...")
 
 
 
 
 
 
 
 
 
39
  btn_ingest_url = gr.Button("Ingest URL")
40
- url_status = gr.Textbox(label="Status", interactive=False)
41
 
 
 
 
 
 
 
42
  gr.Markdown("## Artifacts")
43
- topic = gr.Textbox(label="Topic / prompt")
44
- extra = gr.Textbox(label="Extra prompt (optional)")
 
 
 
 
 
 
 
45
  btn_report = gr.Button("Generate Report")
46
  btn_quiz = gr.Button("Generate Quiz")
47
  btn_podcast = gr.Button("Generate Podcast")
48
 
49
- artifact_status = gr.Textbox(label="Artifact status", interactive=False)
50
- artifacts_list = gr.Dropdown(label="Artifacts", choices=[], interactive=True)
 
 
 
 
 
 
 
 
 
51
  download_btn = gr.Button("Download selected")
52
- download_file = gr.File(label="Download", interactive=False)
53
- podcast_audio = gr.Audio(label="Podcast Audio", interactive=False)
54
 
 
 
 
 
 
 
 
 
 
 
 
55
  with gr.Column(scale=2):
56
- chatbot = gr.Chatbot(height=520, label="Chat (RAG + citations)")
 
 
 
 
 
57
  msg = gr.Textbox(label="Message")
 
58
  send = gr.Button("Send")
59
 
60
- demo.load(on_load, inputs=None, outputs=[username_state, notebook_dd, chatbot, artifacts_list], queue=False)
61
- username_state.change(lambda u: u, inputs=username_state, outputs=user_box, queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- notebook_dd.change(on_switch_notebook, inputs=[username_state, notebook_dd], outputs=[chatbot, artifacts_list], queue=False)
 
 
 
 
 
 
 
 
 
 
64
 
65
- btn_create.click(on_create_notebook, inputs=[username_state, nb_new], outputs=[notebook_dd, chatbot, artifacts_list], queue=False)
66
- btn_rename.click(on_rename_notebook, inputs=[username_state, notebook_dd, nb_rename], outputs=[notebook_dd], queue=False)
67
- btn_delete.click(on_delete_notebook, inputs=[username_state, notebook_dd], outputs=[notebook_dd, chatbot, artifacts_list], queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- btn_ingest_files.click(on_ingest_files, inputs=[username_state, notebook_dd, file_up], outputs=[ingest_status], queue=True)
70
- btn_ingest_url.click(on_ingest_url, inputs=[username_state, notebook_dd, url_in], outputs=[url_status], queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- send.click(on_chat, inputs=[username_state, notebook_dd, chatbot, msg], outputs=[chatbot, msg], queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- btn_report.click(on_report, inputs=[username_state, notebook_dd, topic, extra], outputs=[artifact_status, artifacts_list, download_file], queue=True)
75
- btn_quiz.click(on_quiz, inputs=[username_state, notebook_dd, topic, extra], outputs=[artifact_status, artifacts_list, download_file], queue=True)
76
- btn_podcast.click(on_podcast, inputs=[username_state, notebook_dd, topic, extra], outputs=[artifact_status, artifacts_list, download_file, podcast_audio], queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- download_btn.click(on_download, inputs=[username_state, notebook_dd, artifacts_list], outputs=[download_file], queue=False)
 
 
 
 
 
 
 
 
 
 
79
 
80
  return demo
 
1
  import gradio as gr
2
  from src.frontend.callbacks import (
3
+ ui_bootstrap,
4
+ on_switch_notebook,
5
+ on_create_notebook,
6
+ on_rename_notebook,
7
+ on_delete_notebook,
8
+ on_ingest_files,
9
+ on_ingest_url,
10
+ on_chat,
11
+ on_report,
12
+ on_quiz,
13
+ on_podcast,
14
+ on_download
15
  )
16
  from src.backend.auth import require_login
17
 
18
+
19
  def build_app():
20
+
21
  with gr.Blocks(title="NotebookLM Clone") as demo:
22
+
23
  gr.Markdown("# 📓 NotebookLM Clone (HF Auth + Chroma + RAG)")
24
 
25
  login = gr.LoginButton()
26
+
27
  username_state = gr.State("")
28
 
29
+ # ---------- LOAD ----------
30
  def on_load(request: gr.Request):
31
  username = require_login(request)
32
  dd, chat, arts = ui_bootstrap(username)
33
  return username, dd, chat, arts
34
 
35
  with gr.Row():
36
+
37
+ # ---------- LEFT PANEL ----------
38
  with gr.Column(scale=1):
 
 
39
 
40
+ user_box = gr.Textbox(
41
+ label="User",
42
+ interactive=False
43
+ )
44
+
45
+ notebook_dd = gr.Dropdown(
46
+ label="Notebooks",
47
+ choices=[],
48
+ interactive=True
49
+ )
50
+
51
+ nb_new = gr.Textbox(
52
+ label="Create notebook",
53
+ placeholder="Name"
54
+ )
55
+
56
  btn_create = gr.Button("Create")
57
 
58
+ nb_rename = gr.Textbox(
59
+ label="Rename notebook",
60
+ placeholder="New name"
61
+ )
62
+
63
  btn_rename = gr.Button("Rename")
64
 
65
+ btn_delete = gr.Button(
66
+ "Delete current",
67
+ variant="stop"
68
+ )
69
 
70
+ # ---------- INGEST ----------
71
  gr.Markdown("## Ingest")
72
+
73
+ file_up = gr.File(
74
+ label="Upload PDF/PPTX/TXT",
75
+ file_count="multiple"
76
+ )
77
+
78
  btn_ingest_files = gr.Button("Ingest Files")
 
79
 
80
+ ingest_status = gr.Textbox(
81
+ label="Status",
82
+ interactive=False
83
+ )
84
+
85
+ url_in = gr.Textbox(
86
+ label="URL",
87
+ placeholder="https://..."
88
+ )
89
+
90
  btn_ingest_url = gr.Button("Ingest URL")
 
91
 
92
+ url_status = gr.Textbox(
93
+ label="Status",
94
+ interactive=False
95
+ )
96
+
97
+ # ---------- ARTIFACTS ----------
98
  gr.Markdown("## Artifacts")
99
+
100
+ topic = gr.Textbox(
101
+ label="Topic / prompt"
102
+ )
103
+
104
+ extra = gr.Textbox(
105
+ label="Extra prompt (optional)"
106
+ )
107
+
108
  btn_report = gr.Button("Generate Report")
109
  btn_quiz = gr.Button("Generate Quiz")
110
  btn_podcast = gr.Button("Generate Podcast")
111
 
112
+ artifact_status = gr.Textbox(
113
+ label="Artifact status",
114
+ interactive=False
115
+ )
116
+
117
+ artifacts_list = gr.Dropdown(
118
+ label="Artifacts",
119
+ choices=[],
120
+ interactive=True
121
+ )
122
+
123
  download_btn = gr.Button("Download selected")
 
 
124
 
125
+ download_file = gr.File(
126
+ label="Download",
127
+ interactive=False
128
+ )
129
+
130
+ podcast_audio = gr.Audio(
131
+ label="Podcast Audio",
132
+ interactive=False
133
+ )
134
+
135
+ # ---------- RIGHT PANEL ----------
136
  with gr.Column(scale=2):
137
+
138
+ chatbot = gr.Chatbot(
139
+ height=520,
140
+ label="Chat (RAG + citations)"
141
+ )
142
+
143
  msg = gr.Textbox(label="Message")
144
+
145
  send = gr.Button("Send")
146
 
147
+ # ---------- EVENTS (API DISABLED FIX) ----------
148
+
149
+ demo.load(
150
+ on_load,
151
+ inputs=None,
152
+ outputs=[
153
+ username_state,
154
+ notebook_dd,
155
+ chatbot,
156
+ artifacts_list
157
+ ],
158
+ queue=False,
159
+ api_name=False
160
+ )
161
+
162
+ username_state.change(
163
+ lambda u: u,
164
+ inputs=username_state,
165
+ outputs=user_box,
166
+ queue=False,
167
+ api_name=False
168
+ )
169
+
170
+ notebook_dd.change(
171
+ on_switch_notebook,
172
+ inputs=[username_state, notebook_dd],
173
+ outputs=[chatbot, artifacts_list],
174
+ queue=False,
175
+ api_name=False
176
+ )
177
+
178
+ btn_create.click(
179
+ on_create_notebook,
180
+ inputs=[username_state, nb_new],
181
+ outputs=[
182
+ notebook_dd,
183
+ chatbot,
184
+ artifacts_list
185
+ ],
186
+ queue=False,
187
+ api_name=False
188
+ )
189
+
190
+ btn_rename.click(
191
+ on_rename_notebook,
192
+ inputs=[
193
+ username_state,
194
+ notebook_dd,
195
+ nb_rename
196
+ ],
197
+ outputs=[notebook_dd],
198
+ queue=False,
199
+ api_name=False
200
+ )
201
+
202
+ btn_delete.click(
203
+ on_delete_notebook,
204
+ inputs=[
205
+ username_state,
206
+ notebook_dd
207
+ ],
208
+ outputs=[
209
+ notebook_dd,
210
+ chatbot,
211
+ artifacts_list
212
+ ],
213
+ queue=False,
214
+ api_name=False
215
+ )
216
+
217
+ btn_ingest_files.click(
218
+ on_ingest_files,
219
+ inputs=[
220
+ username_state,
221
+ notebook_dd,
222
+ file_up
223
+ ],
224
+ outputs=[ingest_status],
225
+ queue=True,
226
+ api_name=False
227
+ )
228
 
229
+ btn_ingest_url.click(
230
+ on_ingest_url,
231
+ inputs=[
232
+ username_state,
233
+ notebook_dd,
234
+ url_in
235
+ ],
236
+ outputs=[url_status],
237
+ queue=True,
238
+ api_name=False
239
+ )
240
 
241
+ send.click(
242
+ on_chat,
243
+ inputs=[
244
+ username_state,
245
+ notebook_dd,
246
+ chatbot,
247
+ msg
248
+ ],
249
+ outputs=[
250
+ chatbot,
251
+ msg
252
+ ],
253
+ queue=True,
254
+ api_name=False
255
+ )
256
 
257
+ btn_report.click(
258
+ on_report,
259
+ inputs=[
260
+ username_state,
261
+ notebook_dd,
262
+ topic,
263
+ extra
264
+ ],
265
+ outputs=[
266
+ artifact_status,
267
+ artifacts_list,
268
+ download_file
269
+ ],
270
+ queue=True,
271
+ api_name=False
272
+ )
273
 
274
+ btn_quiz.click(
275
+ on_quiz,
276
+ inputs=[
277
+ username_state,
278
+ notebook_dd,
279
+ topic,
280
+ extra
281
+ ],
282
+ outputs=[
283
+ artifact_status,
284
+ artifacts_list,
285
+ download_file
286
+ ],
287
+ queue=True,
288
+ api_name=False
289
+ )
290
 
291
+ btn_podcast.click(
292
+ on_podcast,
293
+ inputs=[
294
+ username_state,
295
+ notebook_dd,
296
+ topic,
297
+ extra
298
+ ],
299
+ outputs=[
300
+ artifact_status,
301
+ artifacts_list,
302
+ download_file,
303
+ podcast_audio
304
+ ],
305
+ queue=True,
306
+ api_name=False
307
+ )
308
 
309
+ download_btn.click(
310
+ on_download,
311
+ inputs=[
312
+ username_state,
313
+ notebook_dd,
314
+ artifacts_list
315
+ ],
316
+ outputs=[download_file],
317
+ queue=False,
318
+ api_name=False
319
+ )
320
 
321
  return demo