Spaces:
Running
Running
Update backup10.app.py
Browse files- backup10.app.py +80 -25
backup10.app.py
CHANGED
@@ -324,6 +324,7 @@ def search_glossary(query):
|
|
324 |
# π΅οΈββοΈ Searching the glossary for: query
|
325 |
all_results = ""
|
326 |
#st.markdown(f"- {query}")
|
|
|
327 |
|
328 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM
|
329 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
@@ -334,8 +335,11 @@ def search_glossary(query):
|
|
334 |
stream_outputs=True,
|
335 |
api_name="/ask_llm"
|
336 |
)
|
|
|
337 |
st.markdown(result)
|
338 |
st.code(result, language="python", line_numbers=True)
|
|
|
|
|
339 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
340 |
result2 = client.predict(
|
341 |
prompt=query,
|
@@ -343,8 +347,11 @@ def search_glossary(query):
|
|
343 |
stream_outputs=True,
|
344 |
api_name="/ask_llm"
|
345 |
)
|
|
|
346 |
st.markdown(result2)
|
347 |
st.code(result2, language="python", line_numbers=True)
|
|
|
|
|
348 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
349 |
result3 = client.predict(
|
350 |
prompt=query,
|
@@ -352,8 +359,11 @@ def search_glossary(query):
|
|
352 |
stream_outputs=True,
|
353 |
api_name="/ask_llm"
|
354 |
)
|
|
|
355 |
st.markdown(result3)
|
356 |
st.code(result3, language="python", line_numbers=True)
|
|
|
|
|
357 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /update_with_rag_md
|
358 |
response2 = client.predict(
|
359 |
message=query, # str in 'parameter_13' Textbox component
|
@@ -362,10 +372,42 @@ def search_glossary(query):
|
|
362 |
llm_model_picked="mistralai/Mistral-7B-Instruct-v0.2",
|
363 |
api_name="/update_with_rag_md"
|
364 |
)
|
|
|
365 |
st.markdown(response2[0])
|
366 |
-
st.code(response2[0], language="python", line_numbers=True, wrap_lines=True)
|
|
|
|
|
367 |
st.markdown(response2[1])
|
368 |
st.code(response2[1], language="python", line_numbers=True, wrap_lines=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
return result, result2, result3, response2
|
370 |
|
371 |
|
@@ -610,7 +652,7 @@ def main():
|
|
610 |
|
611 |
if documents_to_display:
|
612 |
# π¨ View options - "Different strokes for different folks"
|
613 |
-
view_options = ['Show as Markdown', 'Show as Code Editor', 'Show as
|
614 |
selected_view = st.sidebar.selectbox("Select Viewer/Editor", view_options, index=2)
|
615 |
|
616 |
|
@@ -708,11 +750,9 @@ def main():
|
|
708 |
st.error(f"Error deleting document: {str(e)}")
|
709 |
|
710 |
|
711 |
-
elif selected_view == 'Show as
|
712 |
-
Label = '# βοΈ
|
713 |
-
st.markdown(Label)
|
714 |
-
st.markdown("#### Edit the document fields below:")
|
715 |
-
|
716 |
num_cols = len(documents_to_display)
|
717 |
cols = st.columns(num_cols)
|
718 |
|
@@ -729,33 +769,48 @@ def main():
|
|
729 |
editable_doc = doc.copy()
|
730 |
editable_doc.pop('name', None)
|
731 |
|
732 |
-
|
733 |
doc_str = st.text_area("Document Content (in JSON format)",
|
734 |
value=json.dumps(editable_doc, indent=2),
|
735 |
height=300,
|
736 |
key=f'doc_str_{idx}')
|
737 |
|
738 |
# πΎπ€ Save and AI operations
|
739 |
-
|
740 |
-
|
741 |
-
with col_save:
|
742 |
-
if st.button("πΎ Save Changes", key=f'save_button_{idx}'):
|
743 |
-
try:
|
744 |
-
updated_doc = json.loads(doc_str)
|
745 |
-
updated_doc['id'] = editable_id
|
746 |
-
success, message = update_record(container, updated_doc)
|
747 |
-
if success:
|
748 |
-
st.success(f"Document {updated_doc['id']} saved successfully.")
|
749 |
-
st.session_state.selected_document_id = updated_doc['id']
|
750 |
-
st.rerun()
|
751 |
-
else:
|
752 |
-
st.error(message)
|
753 |
-
except json.JSONDecodeError as e:
|
754 |
-
st.error(f"Invalid JSON: {str(e)} π«")
|
755 |
|
756 |
with col_ai:
|
757 |
if st.button("π€ Run AI", key=f'run_with_ai_button_{idx}'):
|
758 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
759 |
|
760 |
|
761 |
elif selected_view == 'Clone Document':
|
|
|
324 |
# π΅οΈββοΈ Searching the glossary for: query
|
325 |
all_results = ""
|
326 |
#st.markdown(f"- {query}")
|
327 |
+
|
328 |
|
329 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM
|
330 |
client = Client("awacke1/Arxiv-Paper-Search-And-QA-RAG-Pattern")
|
|
|
335 |
stream_outputs=True,
|
336 |
api_name="/ask_llm"
|
337 |
)
|
338 |
+
st.markdown("# Mixtral-8x7B-Instruct-v0.1")
|
339 |
st.markdown(result)
|
340 |
st.code(result, language="python", line_numbers=True)
|
341 |
+
|
342 |
+
|
343 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
344 |
result2 = client.predict(
|
345 |
prompt=query,
|
|
|
347 |
stream_outputs=True,
|
348 |
api_name="/ask_llm"
|
349 |
)
|
350 |
+
st.markdown("# Mistral-7B-Instruct-v0.2")
|
351 |
st.markdown(result2)
|
352 |
st.code(result2, language="python", line_numbers=True)
|
353 |
+
|
354 |
+
|
355 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /ask_llm
|
356 |
result3 = client.predict(
|
357 |
prompt=query,
|
|
|
359 |
stream_outputs=True,
|
360 |
api_name="/ask_llm"
|
361 |
)
|
362 |
+
st.markdown("# Gemma-7b-it")
|
363 |
st.markdown(result3)
|
364 |
st.code(result3, language="python", line_numbers=True)
|
365 |
+
|
366 |
+
|
367 |
# π ArXiv RAG researcher expert ~-<>-~ Paper Summary & Ask LLM - api_name: /update_with_rag_md
|
368 |
response2 = client.predict(
|
369 |
message=query, # str in 'parameter_13' Textbox component
|
|
|
372 |
llm_model_picked="mistralai/Mistral-7B-Instruct-v0.2",
|
373 |
api_name="/update_with_rag_md"
|
374 |
)
|
375 |
+
st.markdown("# Mistral-7B-Instruct-v0.2 update_with_rag_md 0")
|
376 |
st.markdown(response2[0])
|
377 |
+
st.code(response2[0], language="python", line_numbers=True, wrap_lines=True)
|
378 |
+
|
379 |
+
st.markdown("# Mistral-7B-Instruct-v0.2 update_with_rag_md 1")
|
380 |
st.markdown(response2[1])
|
381 |
st.code(response2[1], language="python", line_numbers=True, wrap_lines=True)
|
382 |
+
|
383 |
+
|
384 |
+
# Persist AI Results to Markdown Files
|
385 |
+
try:
|
386 |
+
filename = generate_filename(result, "md")
|
387 |
+
create_file(filename, query, result)
|
388 |
+
st.session_state.chat_history.append({"assistant": query, "ArXiV": result})
|
389 |
+
except:
|
390 |
+
st.markdown('1 error')
|
391 |
+
try:
|
392 |
+
filename = generate_filename(result2, "md")
|
393 |
+
create_file(filename, query, result2)
|
394 |
+
st.session_state.chat_history.append({"assistant": query, "ArXiV": result2})
|
395 |
+
except:
|
396 |
+
st.markdown('2 error')
|
397 |
+
try:
|
398 |
+
filename = generate_filename(response2[0], "md")
|
399 |
+
create_file(filename, query, response2[0])
|
400 |
+
st.session_state.chat_history.append({"assistant": query, "ArXiV": response2[0]})
|
401 |
+
except:
|
402 |
+
st.markdown('3 error')
|
403 |
+
try:
|
404 |
+
filename = generate_filename(response2[1], "md")
|
405 |
+
create_file(filename, query, response2[1])
|
406 |
+
st.session_state.chat_history.append({"assistant": query, "ArXiV": response2[1]})
|
407 |
+
except:
|
408 |
+
st.markdown('4 error')
|
409 |
+
|
410 |
+
|
411 |
return result, result2, result3, response2
|
412 |
|
413 |
|
|
|
652 |
|
653 |
if documents_to_display:
|
654 |
# π¨ View options - "Different strokes for different folks"
|
655 |
+
view_options = ['Show as Markdown', 'Show as Code Editor', 'Show as Run AI', 'Clone Document', 'New Record']
|
656 |
selected_view = st.sidebar.selectbox("Select Viewer/Editor", view_options, index=2)
|
657 |
|
658 |
|
|
|
750 |
st.error(f"Error deleting document: {str(e)}")
|
751 |
|
752 |
|
753 |
+
elif selected_view == 'Show as Run AI':
|
754 |
+
Label = '# βοΈ Run AI with wisdom, save with precision'
|
755 |
+
st.markdown(Label)
|
|
|
|
|
756 |
num_cols = len(documents_to_display)
|
757 |
cols = st.columns(num_cols)
|
758 |
|
|
|
769 |
editable_doc = doc.copy()
|
770 |
editable_doc.pop('name', None)
|
771 |
|
|
|
772 |
doc_str = st.text_area("Document Content (in JSON format)",
|
773 |
value=json.dumps(editable_doc, indent=2),
|
774 |
height=300,
|
775 |
key=f'doc_str_{idx}')
|
776 |
|
777 |
# πΎπ€ Save and AI operations
|
778 |
+
col_ai, col_delete = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
779 |
|
780 |
with col_ai:
|
781 |
if st.button("π€ Run AI", key=f'run_with_ai_button_{idx}'):
|
782 |
+
|
783 |
+
|
784 |
+
|
785 |
+
|
786 |
+
# Experiment to get content fields π€π€π€π€π€π€π€π€π€π€π€π€π€
|
787 |
+
total_docs = len(documents)
|
788 |
+
doc = documents[st.session_state.current_index]
|
789 |
+
values_with_space = []
|
790 |
+
def extract_values2(obj):
|
791 |
+
if isinstance(obj, dict):
|
792 |
+
for k, v in obj.items():
|
793 |
+
extract_values2(v)
|
794 |
+
elif isinstance(obj, list):
|
795 |
+
for item in obj:
|
796 |
+
extract_values2(item)
|
797 |
+
elif isinstance(obj, str):
|
798 |
+
if ' ' in obj:
|
799 |
+
values_with_space.append(obj)
|
800 |
+
extract_values2(doc)
|
801 |
+
#st.markdown("#### π Links for Extracted Texts")
|
802 |
+
for term in values_with_space:
|
803 |
+
display_glossary_entity(term)
|
804 |
+
search_glossary(term)
|
805 |
+
|
806 |
+
#content = json.dumps(doc, indent=2)
|
807 |
+
#st.markdown(f"```json\n{content}\n```")
|
808 |
+
# Experiment to get content fields π€π€π€π€π€π€π€π€π€π€π€π€π€
|
809 |
+
|
810 |
+
|
811 |
+
|
812 |
+
|
813 |
+
#search_glossary(json.dumps(editable_doc, indent=2))
|
814 |
|
815 |
|
816 |
elif selected_view == 'Clone Document':
|