npc0 commited on
Commit
76c7bec
·
verified ·
1 Parent(s): 9b54462

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -30
app.py CHANGED
@@ -1,38 +1,63 @@
1
- import gradio as gr
2
  import subprocess
3
 
4
- examples = [["A qualified alien entered the United States on August 15, 1996. Tell me about their eligibility for Supplemental Security Income (SSI)."],
5
- ["""Question: Which of the following statements most accurately reflects the eligibility requirements for Supplemental Security Income (SSI) as outlined in the Alien Eligibility Under Welfare Reform?
6
- A) To be eligible for SSI, an individual must be a U.S. citizen, with no exceptions for non-citizens.
7
- B) SSI eligibility is extended to all individuals residing in the United States, regardless of their citizenship or immigration status.
8
- C) To be eligible for SSI, an individual must be either a U.S. citizen or a qualified alien.
9
- D) SSI eligibility is determined solely based on financial need, without consideration of citizenship or immigration status."""],
10
- ["""Explanate the Correct Answer: C
11
- Question: Which of the following statements most accurately reflects the eligibility requirements for Supplemental Security Income (SSI) as outlined in the Alien Eligibility Under Welfare Reform?
12
- A) To be eligible for SSI, an individual must be a U.S. citizen, with no exceptions for non-citizens.
13
- B) SSI eligibility is extended to all individuals residing in the United States, regardless of their citizenship or immigration status.
14
- C) To be eligible for SSI, an individual must be either a U.S. citizen or a qualified alien.
15
- D) SSI eligibility is determined solely based on financial need, without consideration of citizenship or immigration status."""]]
16
-
17
- def respond(message, *args, **kwargs):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  command = [
19
  "python", "-m", "graphrag.query",
20
  "--root", "./ragtest",
21
  "--method", "global",
22
- message
23
  ]
24
-
25
- try:
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
- if __name__ == "__main__":
38
- demo.launch(auth=("tester", "8888p4ss"))
 
 
 
 
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})