|
import math |
|
import os |
|
from datetime import datetime |
|
|
|
import openai |
|
import PyPDF2 |
|
import streamlit as st |
|
from openai import OpenAI |
|
|
|
from helper.utils import * |
|
|
|
st.set_page_config(layout="wide", page_title="Document Search using QIMπ€π") |
|
st.header("Document Search using Quantized Influence Measure (QIM)π€π") |
|
st.write("---") |
|
|
|
|
|
|
|
with st.sidebar: |
|
|
|
with st.expander("Instruction Manual π"): |
|
|
|
st.markdown( |
|
""" |
|
# Document Data Chatbot User Manual π€π |
|
|
|
Welcome to the Document Data Chatbot, your interactive assistant for information on the textual "Document Data". This chatbot offers quick and accurate responses to your queries. Follow these steps to interact with the chatbot: |
|
|
|
## Getting Started π |
|
1. **Access the Chatbot**: Launch the Document Data Chatbot on your device. |
|
2. **Start Chatting**: Type your Document Data-related questions in the chat window. Questions can range from dosage to side effects. |
|
3. **Send Your Question**: Submit your query by clicking 'Send' or pressing 'Enter'. |
|
|
|
## Chatting with Document Data Chatbot π€π¬ |
|
- **Ask Anything**: Inquiries about textual composition, usage, storage, or safety are all welcome. |
|
- **Use Simple Language**: Clear and concise questions yield the best results. |
|
- **Wait for the Response**: The chatbot will promptly process and answer your query. |
|
- **Follow-Up Questions**: Feel free to ask additional or new questions anytime. |
|
|
|
## Tips for a Better Experience β¨ |
|
- **Be Specific**: Specific questions help in getting precise answers. |
|
- **Check for Typing Errors**: Correct spelling ensures better understanding by the chatbot. |
|
- **Emoji Use**: Emojis are welcome in your questions! |
|
- **Patience is Key**: Responses may take a moment as the chatbot processes your query. |
|
|
|
## Support and Feedback π€ |
|
- **Need Help?**: Contact our support team for any issues. |
|
- **Share Your Feedback**: Your input is valuable and helps us improve. |
|
|
|
## The Team Behind the App π§βπ»π©βπ» |
|
- **Founders**: Learn about [Peter Yin](https://www.linkedin.com/in/peter-yin-7914ba25/) and [Yiqiao Yin](https://www.linkedin.com/in/yiqiaoyin/), the founders, on LinkedIn. |
|
|
|
Thank you for choosing the Document Data Chatbot. We're here to provide all the information you need about Document Data efficiently. Happy chatting! ππ¬ |
|
""" |
|
) |
|
|
|
|
|
uploaded_files = st.file_uploader( |
|
"Upload documents", accept_multiple_files=True, type=["txt", "pdf"] |
|
) |
|
|
|
|
|
top_n = st.number_input("Insert a number (top n rows to be selected):") |
|
|
|
|
|
clear_button = st.sidebar.button("Clear Conversation", key="clear") |
|
|
|
|
|
st.image(uploaded_files) |
|
|
|
|
|
current_year = current_year() |
|
st.markdown( |
|
f""" |
|
<h6 style='text-align: left;'>Copyright Β© 2010-{current_year} Present Yiqiao Yin</h6> |
|
""", |
|
unsafe_allow_html=True, |
|
) |
|
|
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
|
|
if clear_button: |
|
st.session_state.messages = [] |
|
|
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"]): |
|
st.markdown(message["content"]) |
|
|
|
|
|
|
|
if uploaded_files is None: |
|
|
|
st.info("Upload files to analyze") |
|
|
|
|
|
elif uploaded_files: |
|
|
|
st.sidebar.success(f"{len(uploaded_files)} document(s) loaded...") |
|
|
|
|
|
textify_output = read_and_textify(uploaded_files) |
|
|
|
|
|
documents, sources = textify_output |
|
|
|
|
|
query_database = list_to_nums(documents) |
|
|
|
|
|
refs_tab = query_search( |
|
"pful for understanding federal income", documents, query_database, sources |
|
) |
|
refs_tab.head(math.ceil(top_n)) |
|
|
|
|
|
if prompt := st.chat_input("What is up?"): |
|
|
|
st.chat_message("user").markdown(prompt) |
|
|
|
st.session_state.messages.append({"role": "user", "content": prompt}) |
|
|
|
result = refs_tab |
|
|
|
|
|
with st.chat_message("assistant"): |
|
st.table(result) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": result}) |
|
|