Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,63 @@
|
|
| 1 |
-
import
|
| 2 |
import subprocess
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
command = [
|
| 19 |
"python", "-m", "graphrag.query",
|
| 20 |
"--root", "./ragtest",
|
| 21 |
"--method", "global",
|
| 22 |
-
|
| 23 |
]
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
| 27 |
-
return result.stdout
|
| 28 |
-
except subprocess.CalledProcessError as e:
|
| 29 |
-
return f"Error: {e.stderr}"
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
demo = gr.ChatInterface(
|
| 33 |
-
respond,
|
| 34 |
-
examples=examples)
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import subprocess
|
| 3 |
|
| 4 |
+
st.title("POMS-QA with Knowledge Graph enhancement")
|
| 5 |
+
|
| 6 |
+
def check_password():
|
| 7 |
+
"""Returns `True` if the user had the correct password."""
|
| 8 |
+
|
| 9 |
+
def password_entered():
|
| 10 |
+
"""Checks whether a password entered by the user is correct."""
|
| 11 |
+
if hmac.compare_digest(st.session_state["password"], "8888p4ss"):
|
| 12 |
+
st.session_state["password_correct"] = True
|
| 13 |
+
del st.session_state["password"] # Don't store the password.
|
| 14 |
+
else:
|
| 15 |
+
st.session_state["password_correct"] = False
|
| 16 |
+
|
| 17 |
+
# Return True if the password is validated.
|
| 18 |
+
if st.session_state.get("password_correct", False):
|
| 19 |
+
return True
|
| 20 |
+
|
| 21 |
+
# Show input for password.
|
| 22 |
+
st.text_input(
|
| 23 |
+
"Password", type="password", on_change=password_entered, key="password"
|
| 24 |
+
)
|
| 25 |
+
if "password_correct" in st.session_state:
|
| 26 |
+
st.error("😕 Password incorrect")
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if not check_password():
|
| 31 |
+
st.stop() # Do not continue if check_password is not True.
|
| 32 |
+
|
| 33 |
+
# Initialize chat history
|
| 34 |
+
if "messages" not in st.session_state:
|
| 35 |
+
st.session_state.messages = []
|
| 36 |
+
|
| 37 |
+
# Display chat messages from history on app rerun
|
| 38 |
+
for message in st.session_state.messages:
|
| 39 |
+
with st.chat_message(message["role"]):
|
| 40 |
+
st.markdown(message["content"])
|
| 41 |
+
|
| 42 |
+
# React to user input
|
| 43 |
+
if prompt := st.chat_input("What is up?"):
|
| 44 |
+
# Display user message in chat message container
|
| 45 |
+
with st.chat_message("user"):
|
| 46 |
+
st.markdown(prompt)
|
| 47 |
+
# Add user message to chat history
|
| 48 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 49 |
+
|
| 50 |
command = [
|
| 51 |
"python", "-m", "graphrag.query",
|
| 52 |
"--root", "./ragtest",
|
| 53 |
"--method", "global",
|
| 54 |
+
prompt
|
| 55 |
]
|
| 56 |
+
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
| 57 |
+
response = result.stdout
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# Display assistant response in chat message container
|
| 60 |
+
with st.chat_message("assistant"):
|
| 61 |
+
st.markdown(response)
|
| 62 |
+
# Add assistant response to chat history
|
| 63 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|