Ishaan Shah
commited on
Commit
·
506e049
1
Parent(s):
8e1ed79
Better UI
Browse files
app.py
CHANGED
@@ -126,25 +126,41 @@ def print_array(arr):
|
|
126 |
def html_link_generator(book, page):
|
127 |
bookurl = book_url(book)
|
128 |
url = f"https://diagrams1.s3.ap-south-1.amazonaws.com/anatomybooks/{bookurl}#page={page}"
|
129 |
-
html = f'<iframe src="{url}" width="800" height="600"></iframe>'
|
130 |
# print(url)
|
131 |
-
|
|
|
132 |
|
133 |
def getanswer(question):
|
|
|
|
|
134 |
llm_response = qa_chain(question)
|
135 |
response = process_llm_response(llm_response)
|
136 |
-
sources= print_array(response["sources"])
|
137 |
html= html_link_generator(response["sources"][0]["book"][22:], response["sources"][0]["page"])
|
138 |
# html = """<iframe src="https://diagrams1.s3.ap-south-1.amazonaws.com/anatomybooks/BD+Chaurasia's+Handbook+of+General+Anatomy%2C+4th+Edition.pdf#page=40" width="800" height="600"></iframe>"""
|
139 |
-
return response["result"], sources
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
-
demo = gr.Interface(
|
143 |
-
fn=getanswer,
|
144 |
-
inputs=["text"],
|
145 |
-
outputs=["text", "text", "html"],
|
146 |
-
api="question",
|
147 |
-
title="Medihelp Chatbot",
|
148 |
|
149 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
demo.launch()
|
|
|
126 |
def html_link_generator(book, page):
|
127 |
bookurl = book_url(book)
|
128 |
url = f"https://diagrams1.s3.ap-south-1.amazonaws.com/anatomybooks/{bookurl}#page={page}"
|
129 |
+
# html = f'<iframe src="{url}" width="800" height="600"></iframe>'
|
130 |
# print(url)
|
131 |
+
|
132 |
+
return url
|
133 |
|
134 |
def getanswer(question):
|
135 |
+
if question=="" :
|
136 |
+
return "Please ask a question" , []
|
137 |
llm_response = qa_chain(question)
|
138 |
response = process_llm_response(llm_response)
|
|
|
139 |
html= html_link_generator(response["sources"][0]["book"][22:], response["sources"][0]["page"])
|
140 |
# html = """<iframe src="https://diagrams1.s3.ap-south-1.amazonaws.com/anatomybooks/BD+Chaurasia's+Handbook+of+General+Anatomy%2C+4th+Edition.pdf#page=40" width="800" height="600"></iframe>"""
|
141 |
+
return response["result"], response['sources']
|
142 |
|
143 |
+
def makevisible(source1,source2,source3):
|
144 |
+
return{
|
145 |
+
source1: gr.update(visible=True),
|
146 |
+
source2: gr.update(visible=True),
|
147 |
+
source3: gr.update(visible=True)
|
148 |
+
}
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
+
with gr.Blocks() as demo:
|
152 |
+
with gr.Row():
|
153 |
+
with gr.Column(scale=1, min_width=600):
|
154 |
+
question = gr.Textbox(label="Question")
|
155 |
+
submitbtn = gr.Button("Submit").style(full_width=True)
|
156 |
+
answer = gr.Textbox(label="Answer", interactive=False)
|
157 |
+
sources = gr.Json(label="Sources", interactive=False)
|
158 |
+
source1 = gr.Button(label="Source 1", visible=False)
|
159 |
+
source2 = gr.Button(label="Source 2", visible=False)
|
160 |
+
source3 = gr.Button(label="Source 3", visible=False)
|
161 |
+
|
162 |
+
submitbtn.click(fn=getanswer, inputs=[question], outputs=[answer, sources], api_name="question")
|
163 |
+
# source1.click(fn=None, _js=f"""window.open('"""+"""', target="_blank");""")
|
164 |
+
# sources.change(make_source_buttons, [sources, source1, source2, source3], [source1,source2,source3])
|
165 |
+
|
166 |
demo.launch()
|