JARVISXIRONMAN commited on
Commit
fed4ac9
·
verified ·
1 Parent(s): 1399121

Create components/validator.py

Browse files
Files changed (1) hide show
  1. 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.runnables import Runnable
6
- from langchain_groq import ChatGroq
7
- from utils.session import get_canvas_data
8
- from utils.prompts import VALIDATOR_PROMPT
9
-
10
 
11
  def run_validator():
12
- st.header("✅ Validate Your Canvas")
 
 
 
13
 
14
- canvas = get_canvas_data()
15
- if not canvas:
16
  st.warning("Please complete the Canvas Assistant first.")
17
  return
18
 
19
- # Display user input for reference
20
- st.subheader("🧾 Your Canvas Summary")
21
- for section, content in canvas.items():
22
- st.markdown(f"**{section}**")
23
- st.info(content)
24
-
25
- with st.spinner("Analyzing your canvas..."):
26
- # Prompt and chain setup
27
- prompt = ChatPromptTemplate.from_template(
28
- VALIDATOR_PROMPT + "\n\nCanvas Data:\n{input}"
29
- )
30
-
31
- chain: Runnable = prompt | ChatGroq(model="llama3-8b-8192", temperature=0.3)
32
- full_canvas_text = "\n".join([f"{k}: {v}" for k, v in canvas.items()])
33
- validation_result = chain.invoke({"input": full_canvas_text})
34
-
35
- st.subheader("📊 Validation Result")
36
- st.success(validation_result.content)
 
 
 
 
 
 
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)