Spaces:
Sleeping
Sleeping
feat(QuestionModel): Complete for deploy
Browse files- src/graph/__pycache__/__init__.cpython-312.pyc +0 -0
- src/graph/__pycache__/graph_builder.cpython-312.pyc +0 -0
- src/graph/__pycache__/state_vector_nodes.cpython-312.pyc +0 -0
- src/llm/__pycache__/__init__.cpython-312.pyc +0 -0
- src/llm/__pycache__/llm_setup.cpython-312.pyc +0 -0
- src/state/__pycache__/__init__.cpython-312.pyc +0 -0
- src/state/__pycache__/state.cpython-312.pyc +0 -0
- src/streamlit_app.py +54 -2
- src/streamlitui/__pycache__/__init__.cpython-312.pyc +0 -0
- src/streamlitui/__pycache__/constants.cpython-312.pyc +0 -0
src/graph/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/src/graph/__pycache__/__init__.cpython-312.pyc and b/src/graph/__pycache__/__init__.cpython-312.pyc differ
|
|
|
src/graph/__pycache__/graph_builder.cpython-312.pyc
CHANGED
|
Binary files a/src/graph/__pycache__/graph_builder.cpython-312.pyc and b/src/graph/__pycache__/graph_builder.cpython-312.pyc differ
|
|
|
src/graph/__pycache__/state_vector_nodes.cpython-312.pyc
CHANGED
|
Binary files a/src/graph/__pycache__/state_vector_nodes.cpython-312.pyc and b/src/graph/__pycache__/state_vector_nodes.cpython-312.pyc differ
|
|
|
src/llm/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/src/llm/__pycache__/__init__.cpython-312.pyc and b/src/llm/__pycache__/__init__.cpython-312.pyc differ
|
|
|
src/llm/__pycache__/llm_setup.cpython-312.pyc
CHANGED
|
Binary files a/src/llm/__pycache__/llm_setup.cpython-312.pyc and b/src/llm/__pycache__/llm_setup.cpython-312.pyc differ
|
|
|
src/state/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/src/state/__pycache__/__init__.cpython-312.pyc and b/src/state/__pycache__/__init__.cpython-312.pyc differ
|
|
|
src/state/__pycache__/state.cpython-312.pyc
CHANGED
|
Binary files a/src/state/__pycache__/state.cpython-312.pyc and b/src/state/__pycache__/state.cpython-312.pyc differ
|
|
|
src/streamlit_app.py
CHANGED
|
@@ -1,15 +1,23 @@
|
|
| 1 |
import configparser
|
| 2 |
import streamlit as st
|
| 3 |
from typing import List, Optional
|
|
|
|
|
|
|
| 4 |
|
| 5 |
from streamlitui.constants import unsdg_countries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
class StreamlitConfigUI:
|
| 7 |
|
| 8 |
"""
|
| 9 |
A Streamlit UI class that uses ConfigParser to load settings from an INI file.
|
| 10 |
"""
|
| 11 |
|
| 12 |
-
def __init__(self, config_file: str = "./
|
| 13 |
"""
|
| 14 |
Initialize the UI class with configuration file.
|
| 15 |
|
|
@@ -68,10 +76,54 @@ class LoadStreamlitUI:
|
|
| 68 |
self.user_controls["selected_usecase"]=st.selectbox("Select Usecases",usecase_options)
|
| 69 |
self.user_controls['UN SDG Country']= st.selectbox("Choose a country (start typing to search):",options=[""] + self.unsdg_countries)
|
| 70 |
return self.user_controls
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
if __name__=='__main__':
|
| 73 |
ui=LoadStreamlitUI()
|
| 74 |
user_input=ui.load_streamlit_ui()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
if not user_input:
|
| 76 |
st.error("Error: Failed to load user input from the UI.")
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import configparser
|
| 2 |
import streamlit as st
|
| 3 |
from typing import List, Optional
|
| 4 |
+
from transformers import DistilBertTokenizerFast, TFDistilBertForSequenceClassification
|
| 5 |
+
from langchain_core.messages import AnyMessage, AIMessage,SystemMessage, HumanMessage,AIMessageChunk
|
| 6 |
|
| 7 |
from streamlitui.constants import unsdg_countries
|
| 8 |
+
from llm.llm_setup import ModelSelection
|
| 9 |
+
import pandas as pd
|
| 10 |
+
from state.state import StateVector
|
| 11 |
+
from graph.state_vector_nodes import question_model
|
| 12 |
+
from graph.graph_builder import BuildGraphOptions
|
| 13 |
+
import re
|
| 14 |
class StreamlitConfigUI:
|
| 15 |
|
| 16 |
"""
|
| 17 |
A Streamlit UI class that uses ConfigParser to load settings from an INI file.
|
| 18 |
"""
|
| 19 |
|
| 20 |
+
def __init__(self, config_file: str = "./streamlitui/uiconfigfile.ini"):
|
| 21 |
"""
|
| 22 |
Initialize the UI class with configuration file.
|
| 23 |
|
|
|
|
| 76 |
self.user_controls["selected_usecase"]=st.selectbox("Select Usecases",usecase_options)
|
| 77 |
self.user_controls['UN SDG Country']= st.selectbox("Choose a country (start typing to search):",options=[""] + self.unsdg_countries)
|
| 78 |
return self.user_controls
|
| 79 |
+
def display_result_on_ui( state_graph,mode="Question Refining Mode:"):
|
| 80 |
+
if mode =="Question Refining Mode:":
|
| 81 |
+
for event in graph.stream({'messages':("user",user_message)}):
|
| 82 |
+
print(event.values())
|
| 83 |
+
for value in event.values():
|
| 84 |
+
print(value['messages'])
|
| 85 |
+
with st.chat_message("user"):
|
| 86 |
+
st.write(user_message)
|
| 87 |
+
with st.chat_message("SDG AI Assistant"):
|
| 88 |
+
st.write(value["messages"].content)
|
| 89 |
|
| 90 |
if __name__=='__main__':
|
| 91 |
ui=LoadStreamlitUI()
|
| 92 |
user_input=ui.load_streamlit_ui()
|
| 93 |
+
LLM_Selection=ModelSelection(user_input)
|
| 94 |
+
if user_input["GENAI_API_KEY"]:llm=LLM_Selection.setup_llm_model()
|
| 95 |
+
loaded_tokenizer = DistilBertTokenizerFast.from_pretrained('./train_bert/topic_classifier_model')
|
| 96 |
+
loaded_model = TFDistilBertForSequenceClassification.from_pretrained('./train_bert/topic_classifier_model')
|
| 97 |
+
df_keys=pd.read_csv('train_bert/training_data/Keyword_Patterns.csv')
|
| 98 |
+
|
| 99 |
if not user_input:
|
| 100 |
st.error("Error: Failed to load user input from the UI.")
|
| 101 |
+
#Input prompt
|
| 102 |
+
user_message = st.chat_input("Ask me a question or give me keywords to kick off a query about a UN SDG Goal:")
|
| 103 |
+
|
| 104 |
+
if user_message and user_input['UN SDG Country']:
|
| 105 |
+
state=StateVector(country=user_input['UN SDG Country'], seed_question=user_message, messages=[])
|
| 106 |
+
|
| 107 |
+
SmartQuestions=question_model(#StateVector=state,
|
| 108 |
+
loaded_tokenizer=loaded_tokenizer,
|
| 109 |
+
loaded_model=loaded_model, llm=llm, df_keys=df_keys)
|
| 110 |
+
builder=BuildGraphOptions(SmartQuestions)
|
| 111 |
+
graph=builder.build_graph()
|
| 112 |
+
with st.chat_message("assistant"):
|
| 113 |
+
intro="Hello, I am an assistant designed to help you learn about the 17 UN SDG goals listed here: https://sdgs.un.org/goals.\
|
| 114 |
+
You can ask me about any of the goals or specific topics, and I will provide you with information and resources related to them.\
|
| 115 |
+
I can also help you create a question related to the SDGs based on your input.\
|
| 116 |
+
Please provide me with a topic or question related to the SDGs and select a country, and I will do my best to assist you." #,
|
| 117 |
+
st.write(intro)
|
| 118 |
+
initial_input = {'country': user_input['UN SDG Country'], 'seed_question': user_message}
|
| 119 |
+
with st.chat_message("user"):st.write(user_message)
|
| 120 |
+
with st.chat_message("assistant"):
|
| 121 |
+
message_placeholder = st.empty()
|
| 122 |
+
accumulated_content = ""
|
| 123 |
+
for chunk in graph.stream(initial_input, stream_mode='messages'):
|
| 124 |
+
message, meta=chunk
|
| 125 |
+
if isinstance(message, AIMessage):
|
| 126 |
+
accumulated_content += message.content
|
| 127 |
+
message_placeholder.write(accumulated_content)
|
| 128 |
+
else:
|
| 129 |
+
print("Deep Rishsearch")
|
src/streamlitui/__pycache__/__init__.cpython-312.pyc
CHANGED
|
Binary files a/src/streamlitui/__pycache__/__init__.cpython-312.pyc and b/src/streamlitui/__pycache__/__init__.cpython-312.pyc differ
|
|
|
src/streamlitui/__pycache__/constants.cpython-312.pyc
CHANGED
|
Binary files a/src/streamlitui/__pycache__/constants.cpython-312.pyc and b/src/streamlitui/__pycache__/constants.cpython-312.pyc differ
|
|
|