Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,7 +88,7 @@ def get_conversation_chain(vectorstore):
|
|
| 88 |
- ConversationalRetrievalChain: An initialized conversational chain object.
|
| 89 |
"""
|
| 90 |
try:
|
| 91 |
-
llm = ChatOpenAI(model_name="gpt-
|
| 92 |
memory = ConversationBufferMemory(
|
| 93 |
memory_key="chat_history", return_messages=True
|
| 94 |
)
|
|
@@ -133,14 +133,15 @@ def get_user_chat_count(user_id):
|
|
| 133 |
)
|
| 134 |
cursor = conn.cursor()
|
| 135 |
|
| 136 |
-
cursor.execute("SELECT count FROM
|
| 137 |
result = cursor.fetchone()
|
| 138 |
if result:
|
| 139 |
return result[0]
|
| 140 |
else:
|
| 141 |
# Insert a new row for the user if not found
|
| 142 |
cursor.execute(
|
| 143 |
-
"INSERT INTO
|
|
|
|
| 144 |
)
|
| 145 |
conn.commit()
|
| 146 |
return 0
|
|
@@ -216,32 +217,6 @@ def chat(slug, user_id):
|
|
| 216 |
flow and displaying the chat history.
|
| 217 |
Restricts chat based on user group and chat count.
|
| 218 |
"""
|
| 219 |
-
try:
|
| 220 |
-
conn = mysql.connector.connect(
|
| 221 |
-
user=os.getenv("SQL_USER"),
|
| 222 |
-
password=os.getenv("SQL_PWD"),
|
| 223 |
-
host=os.getenv("SQL_HOST"),
|
| 224 |
-
database="Birdseye_DB",
|
| 225 |
-
)
|
| 226 |
-
cursor = conn.cursor()
|
| 227 |
-
|
| 228 |
-
# Execute a query
|
| 229 |
-
cursor.execute("SELECT ocr_text FROM birdseye_temp WHERE slug = %s", (slug,))
|
| 230 |
-
|
| 231 |
-
# Fetch the results
|
| 232 |
-
rows = cursor.fetchall()
|
| 233 |
-
text = ""
|
| 234 |
-
for row in rows:
|
| 235 |
-
if row[0]:
|
| 236 |
-
text += row[0]
|
| 237 |
-
|
| 238 |
-
except mysql.connector.Error as err:
|
| 239 |
-
st.error(f"Error: {err}")
|
| 240 |
-
return
|
| 241 |
-
finally:
|
| 242 |
-
if conn.is_connected():
|
| 243 |
-
cursor.close()
|
| 244 |
-
conn.close()
|
| 245 |
|
| 246 |
text_chunks = get_text_chunks(get_pdf_text(slug))
|
| 247 |
vectorstore = get_vectorstore(text_chunks)
|
|
|
|
| 88 |
- ConversationalRetrievalChain: An initialized conversational chain object.
|
| 89 |
"""
|
| 90 |
try:
|
| 91 |
+
llm = ChatOpenAI(model_name="gpt-4o")
|
| 92 |
memory = ConversationBufferMemory(
|
| 93 |
memory_key="chat_history", return_messages=True
|
| 94 |
)
|
|
|
|
| 133 |
)
|
| 134 |
cursor = conn.cursor()
|
| 135 |
|
| 136 |
+
cursor.execute("SELECT count FROM birdseye_chat WHERE user_id = %s", (user_id,))
|
| 137 |
result = cursor.fetchone()
|
| 138 |
if result:
|
| 139 |
return result[0]
|
| 140 |
else:
|
| 141 |
# Insert a new row for the user if not found
|
| 142 |
cursor.execute(
|
| 143 |
+
"INSERT INTO birdseye_chat (user_id, count) VALUES (%s, %s)",
|
| 144 |
+
(user_id, 0),
|
| 145 |
)
|
| 146 |
conn.commit()
|
| 147 |
return 0
|
|
|
|
| 217 |
flow and displaying the chat history.
|
| 218 |
Restricts chat based on user group and chat count.
|
| 219 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
text_chunks = get_text_chunks(get_pdf_text(slug))
|
| 222 |
vectorstore = get_vectorstore(text_chunks)
|