Prat0 commited on
Commit
a619ed0
·
verified ·
1 Parent(s): 98576fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -50
app.py CHANGED
@@ -12,7 +12,6 @@ from llama_index.embeddings.gemini import GeminiEmbedding
12
  from llama_index.core.memory import ChatMemoryBuffer
13
  from llama_index.readers.web import FireCrawlWebReader
14
  from llama_index.core import SummaryIndex
15
- import streamlit_analytics
16
 
17
  # Setup functions
18
  def embed_setup():
@@ -85,52 +84,51 @@ if 'chat_history' not in st.query_params:
85
  if 'last_response' not in st.query_params:
86
  st.query_params['last_response'] = None
87
 
88
- with streamlit_analytics.track():
89
- # URL input for document ingestion
90
- url = st.text_input("Enter URL to crawl and ingest documents:")
91
-
92
- # Combined Ingest and Setup button
93
- if st.button("Ingest and Setup"):
94
- if url:
95
- with st.spinner("Crawling, ingesting documents, and setting up query engine..."):
96
- st.query_params['documents'] = ingest_documents(url)
97
- embed_setup()
98
- client = qdrant_setup()
99
- llm = llm_setup()
100
- vector_store = QdrantVectorStore(client=client, collection_name=os.getenv("COLLECTION_NAME"))
101
- index = VectorStoreIndex.from_documents(st.query_params['documents'], vector_store=vector_store)
102
- st.query_params['chat_engine'] = query_index(index)
103
- st.success(f"Documents ingested from {url} and query engine setup completed successfully!")
104
- else:
105
- st.error("Please enter a URL")
106
-
107
- # Query input
108
- query = st.text_input("Enter your query:")
109
-
110
- # Search button
111
- if st.button("Search"):
112
- if st.query_params['chat_engine'] is None:
113
- st.error("Please complete the setup first")
114
- elif query:
115
- with st.spinner("Searching..."):
116
- response = st.query_params['chat_engine'].chat(query)
117
-
118
- # Add the query and response to chat history
119
- st.query_params['chat_history'].append(("User", query))
120
- st.query_params['chat_history'].append(("Assistant", str(response.response)))
121
-
122
- # Display the most recent response prominently
123
- st.subheader("Assistant's Response:")
124
- st.write(response.response)
125
- else:
126
- st.error("Please enter a query")
127
-
128
- # Sidebar for chat history
129
- st.sidebar.title("Chat History")
130
- for role, message in st.query_params['chat_history']:
131
- st.sidebar.text(f"{role}: {message}")
132
-
133
- # Clear chat history button in sidebar
134
- if st.sidebar.button("Clear Chat History"):
135
- st.query_params['chat_history'] = []
136
- st.sidebar.success("Chat history cleared!")
 
12
  from llama_index.core.memory import ChatMemoryBuffer
13
  from llama_index.readers.web import FireCrawlWebReader
14
  from llama_index.core import SummaryIndex
 
15
 
16
  # Setup functions
17
  def embed_setup():
 
84
  if 'last_response' not in st.query_params:
85
  st.query_params['last_response'] = None
86
 
87
+ # URL input for document ingestion
88
+ url = st.text_input("Enter URL to crawl and ingest documents:")
89
+
90
+ # Combined Ingest and Setup button
91
+ if st.button("Ingest and Setup"):
92
+ if url:
93
+ with st.spinner("Crawling, ingesting documents, and setting up query engine..."):
94
+ st.query_params['documents'] = ingest_documents(url)
95
+ embed_setup()
96
+ client = qdrant_setup()
97
+ llm = llm_setup()
98
+ vector_store = QdrantVectorStore(client=client, collection_name=os.getenv("COLLECTION_NAME"))
99
+ index = VectorStoreIndex.from_documents(st.query_params['documents'], vector_store=vector_store)
100
+ st.query_params['chat_engine'] = query_index(index)
101
+ st.success(f"Documents ingested from {url} and query engine setup completed successfully!")
102
+ else:
103
+ st.error("Please enter a URL")
104
+
105
+ # Query input
106
+ query = st.text_input("Enter your query:")
107
+
108
+ # Search button
109
+ if st.button("Search"):
110
+ if st.query_params['chat_engine'] is None:
111
+ st.error("Please complete the setup first")
112
+ elif query:
113
+ with st.spinner("Searching..."):
114
+ response = st.query_params['chat_engine'].chat(query)
115
+
116
+ # Add the query and response to chat history
117
+ st.query_params['chat_history'].append(("User", query))
118
+ st.query_params['chat_history'].append(("Assistant", str(response.response)))
119
+
120
+ # Display the most recent response prominently
121
+ st.subheader("Assistant's Response:")
122
+ st.write(response.response)
123
+ else:
124
+ st.error("Please enter a query")
125
+
126
+ # Sidebar for chat history
127
+ st.sidebar.title("Chat History")
128
+ for role, message in st.query_params['chat_history']:
129
+ st.sidebar.text(f"{role}: {message}")
130
+
131
+ # Clear chat history button in sidebar
132
+ if st.sidebar.button("Clear Chat History"):
133
+ st.query_params['chat_history'] = []
134
+ st.sidebar.success("Chat history cleared!")