wylum commited on
Commit
ee7ba6e
·
verified ·
1 Parent(s): 851c029

Update app-azure.py

Browse files
Files changed (1) hide show
  1. app-azure.py +41 -1
app-azure.py CHANGED
@@ -103,6 +103,39 @@ def enable_api_box():
103
  return enable_box
104
  """
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  def add_text(history, text: str):
107
  if not text:
108
  raise gr.Error("enter text")
@@ -346,11 +379,12 @@ with gr.Blocks() as demo:
346
  vector_db = gr.State()
347
  qa_chain = gr.State()
348
  collection_name = gr.State()
 
349
  #N = gr.Number()
350
  #count = gr.Number()
351
 
352
  N = 0
353
- count = 0
354
 
355
  #chat_history = gr.State()
356
  #chat_history: list = []
@@ -402,6 +436,12 @@ with gr.Blocks() as demo:
402
  ],
403
  )
404
  """
 
 
 
 
 
 
405
 
406
  btn.upload(
407
  fn=purge_chat_and_render_first,
 
103
  return enable_box
104
  """
105
 
106
+ def set_DRlink(dr_link: str):
107
+ print("DR Link set")
108
+ chat_history = []
109
+ history = []
110
+ #count = 0
111
+ dr_link_url = 'https://repository.lib.cuhk.edu.hk/en/islandora/object/cuhk%3A'+ dr_link + '/datastream/PDF/'
112
+ app.DR_LINK = dr_link
113
+ hdr = { 'User-Agent' : user_agent }
114
+
115
+ response = requests.get(dr_link_url, headers=hdr)
116
+ #print(response.status_code)
117
+ #print(response.text)
118
+ file_Path = dr_link + ".pdf"
119
+ file = None
120
+ image = None
121
+ if response.status_code == 200:
122
+ with open(file_Path, 'wb') as file:
123
+ file.write(response.content)
124
+ print('File downloaded successfully')
125
+
126
+
127
+ # Use PyMuPDF to render the first page of the uploaded document
128
+ if file:
129
+ image, txt = purge_chat_and_render_first(file)
130
+ else:
131
+ raise gr.Error("Error reading DR Link!")
132
+
133
+
134
+
135
+ #return disable_box
136
+ #return dr_link
137
+ return dr_link, image, [], file
138
+
139
  def add_text(history, text: str):
140
  if not text:
141
  raise gr.Error("enter text")
 
379
  vector_db = gr.State()
380
  qa_chain = gr.State()
381
  collection_name = gr.State()
382
+ DR_LINK = gr.State()
383
  #N = gr.Number()
384
  #count = gr.Number()
385
 
386
  N = 0
387
+ #count = 0
388
 
389
  #chat_history = gr.State()
390
  #chat_history: list = []
 
436
  ],
437
  )
438
  """
439
+ dr_link.submit(
440
+ fn=set_DRlink,
441
+ inputs=[dr_link],
442
+ #outputs=[dr_link,],
443
+ outputs=[dr_link, show_img, chatbot, btn],
444
+ )
445
 
446
  btn.upload(
447
  fn=purge_chat_and_render_first,