Spaces:
Running
Running
bug fix
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from unstructured.partition.pdf import partition_pdf
|
3 |
import pymupdf
|
@@ -217,7 +218,8 @@ def conversation(vectordb_client, msg, num_context, img_context, history):
|
|
217 |
results = text_collection.query(
|
218 |
query_texts=[msg], include=["documents"], n_results=num_context
|
219 |
)["documents"][0]
|
220 |
-
|
|
|
221 |
similar_images = image_collection.query(
|
222 |
query_texts=[msg],
|
223 |
include=["metadatas", "distances", "documents"],
|
@@ -249,7 +251,7 @@ def conversation(vectordb_client, msg, num_context, img_context, history):
|
|
249 |
context = "\n\n".join(results)
|
250 |
# references = [gr.Textbox(i, visible=True, interactive=False) for i in results]
|
251 |
response = llm(prompt.format(context=context, question=msg, images=img_desc))
|
252 |
-
|
253 |
|
254 |
|
255 |
def check_validity_and_llm(session_states):
|
@@ -370,11 +372,12 @@ with gr.Blocks(css=CSS) as demo:
|
|
370 |
with gr.Accordion("Text References", open=False):
|
371 |
# text_context = gr.Row()
|
372 |
|
373 |
-
@gr.render(inputs=
|
374 |
-
def gen_refs(
|
375 |
-
|
|
|
376 |
for i in range(n):
|
377 |
-
gr.Textbox(label=f"
|
378 |
|
379 |
|
380 |
with gr.Row():
|
@@ -408,7 +411,7 @@ with gr.Blocks(css=CSS) as demo:
|
|
408 |
submit_btn.click(
|
409 |
conversation,
|
410 |
[vectordb, msg, num_context, img_context, chatbot],
|
411 |
-
[chatbot,
|
412 |
)
|
413 |
|
414 |
|
@@ -416,4 +419,4 @@ with gr.Blocks(css=CSS) as demo:
|
|
416 |
|
417 |
next_p1.click(check_validity_and_llm, session_states, tabs)
|
418 |
if __name__ == "__main__":
|
419 |
-
demo.launch(
|
|
|
1 |
+
%%writefile app.py
|
2 |
import gradio as gr
|
3 |
from unstructured.partition.pdf import partition_pdf
|
4 |
import pymupdf
|
|
|
218 |
results = text_collection.query(
|
219 |
query_texts=[msg], include=["documents"], n_results=num_context
|
220 |
)["documents"][0]
|
221 |
+
# print(results)
|
222 |
+
# print("R"*100)
|
223 |
similar_images = image_collection.query(
|
224 |
query_texts=[msg],
|
225 |
include=["metadatas", "distances", "documents"],
|
|
|
251 |
context = "\n\n".join(results)
|
252 |
# references = [gr.Textbox(i, visible=True, interactive=False) for i in results]
|
253 |
response = llm(prompt.format(context=context, question=msg, images=img_desc))
|
254 |
+
return history + [(msg, response)], results, images_and_locs
|
255 |
|
256 |
|
257 |
def check_validity_and_llm(session_states):
|
|
|
372 |
with gr.Accordion("Text References", open=False):
|
373 |
# text_context = gr.Row()
|
374 |
|
375 |
+
@gr.render(inputs=references)
|
376 |
+
def gen_refs(references):
|
377 |
+
# print(references)
|
378 |
+
n = len(references)
|
379 |
for i in range(n):
|
380 |
+
gr.Textbox(label=f"Reference-{i+1}", value=references[i], lines=3)
|
381 |
|
382 |
|
383 |
with gr.Row():
|
|
|
411 |
submit_btn.click(
|
412 |
conversation,
|
413 |
[vectordb, msg, num_context, img_context, chatbot],
|
414 |
+
[chatbot,references ,ret_images],
|
415 |
)
|
416 |
|
417 |
|
|
|
419 |
|
420 |
next_p1.click(check_validity_and_llm, session_states, tabs)
|
421 |
if __name__ == "__main__":
|
422 |
+
demo.launch()
|