Spaces:
Sleeping
Sleeping
Create components/validator.py
Browse files- components/validator.py +26 -23
components/validator.py
CHANGED
|
@@ -1,33 +1,36 @@
|
|
| 1 |
# components/validator.py
|
| 2 |
|
| 3 |
import streamlit as st
|
| 4 |
-
from langchain_core.output_parsers import StrOutputParser
|
| 5 |
from langchain_core.prompts import ChatPromptTemplate
|
|
|
|
| 6 |
from langchain_groq import ChatGroq
|
| 7 |
-
from utils.session import
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def run_validator():
|
| 10 |
-
st.
|
| 11 |
-
canvas_data = load_from_json("canvas_data")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
return
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
{
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
| 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)
|