Spaces:
Sleeping
Sleeping
Create components/validator.py
Browse files- components/validator.py +30 -28
components/validator.py
CHANGED
|
@@ -1,36 +1,38 @@
|
|
| 1 |
-
# components/validator.py
|
| 2 |
-
|
| 3 |
import streamlit as st
|
| 4 |
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
-
from langchain_core.
|
| 6 |
-
from
|
| 7 |
-
from utils.
|
| 8 |
-
from utils.
|
| 9 |
-
|
| 10 |
|
| 11 |
def run_validator():
|
| 12 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
if not canvas:
|
| 16 |
st.warning("Please complete the Canvas Assistant first.")
|
| 17 |
return
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from langchain_core.prompts import ChatPromptTemplate
|
| 3 |
+
from langchain_core.messages import AIMessage
|
| 4 |
+
from langchain_community.chat_models import ChatGroq
|
| 5 |
+
from utils.prompts import VALIDATION_PROMPT
|
| 6 |
+
from utils.session import get_state_value, update_state
|
|
|
|
| 7 |
|
| 8 |
def run_validator():
|
| 9 |
+
st.title("✅ Validate Canvas")
|
| 10 |
+
st.markdown("AI will evaluate your business model for clarity and coherence.")
|
| 11 |
+
|
| 12 |
+
responses = get_state_value("canvas_responses", {})
|
| 13 |
|
| 14 |
+
if not responses or len(responses) < 10:
|
|
|
|
| 15 |
st.warning("Please complete the Canvas Assistant first.")
|
| 16 |
return
|
| 17 |
|
| 18 |
+
canvas_data = ""
|
| 19 |
+
for i in range(10):
|
| 20 |
+
canvas_data += f"{responses[str(i)]}\n"
|
| 21 |
+
|
| 22 |
+
prompt = ChatPromptTemplate.from_messages([
|
| 23 |
+
("system", VALIDATION_PROMPT),
|
| 24 |
+
("human", "{input}")
|
| 25 |
+
])
|
| 26 |
+
|
| 27 |
+
chain = prompt | ChatGroq(model_name="llama3-8b-8192", temperature=0.4)
|
| 28 |
+
|
| 29 |
+
if st.button("Validate Canvas"):
|
| 30 |
+
with st.spinner("Validating your business model..."):
|
| 31 |
+
result = chain.invoke({"input": canvas_data})
|
| 32 |
+
update_state("validation_result", result.content)
|
| 33 |
+
st.success("Canvas validated successfully!")
|
| 34 |
+
|
| 35 |
+
validation_result = get_state_value("validation_result", None)
|
| 36 |
+
if validation_result:
|
| 37 |
+
st.markdown("### 🔎 Validation Result:")
|
| 38 |
+
st.markdown(validation_result)
|