Spaces:
Runtime error
Runtime error
shravya commited on
Commit ·
01c715d
1
Parent(s): 3ce031b
added helpful or not button in feedback
Browse files- ui/til_feedback.py +71 -26
- workflows/utils/feedback.py +1 -1
ui/til_feedback.py
CHANGED
|
@@ -2,10 +2,10 @@ import streamlit as st
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
from workflows.til import TilCrew
|
| 4 |
from streamlit_extras.capture import stdout
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
|
|
|
| 9 |
def main():
|
| 10 |
st.markdown("<div class='container'>", unsafe_allow_html=True)
|
| 11 |
|
|
@@ -46,29 +46,74 @@ def main():
|
|
| 46 |
)
|
| 47 |
|
| 48 |
if st.button("Get Feedback"):
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
main()
|
|
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
from workflows.til import TilCrew
|
| 4 |
from streamlit_extras.capture import stdout
|
| 5 |
+
from langsmith import Client
|
| 6 |
+
from workflows.utils.feedback import Feedback
|
|
|
|
| 7 |
|
| 8 |
+
load_dotenv()
|
| 9 |
def main():
|
| 10 |
st.markdown("<div class='container'>", unsafe_allow_html=True)
|
| 11 |
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
if st.button("Get Feedback"):
|
| 49 |
+
with st.status(
|
| 50 |
+
"🤖 **Analysing TIL...**", state="running", expanded=True
|
| 51 |
+
) as status:
|
| 52 |
+
with st.container(height=500, border=False):
|
| 53 |
+
log_container = st.empty()
|
| 54 |
+
with stdout(log_container.code, terminator=""):
|
| 55 |
+
feedback = TilCrew()
|
| 56 |
+
inputs = {"content": til_content}
|
| 57 |
+
results = feedback.kickoff(inputs=inputs)
|
| 58 |
+
status.update(
|
| 59 |
+
label="✅ Feedback ready!",
|
| 60 |
+
state="complete",
|
| 61 |
+
expanded=False,
|
| 62 |
+
)
|
| 63 |
+
st.session_state.results = results
|
| 64 |
+
st.session_state.run_id = results["run_id"]
|
| 65 |
+
clear_feedback_state(results)
|
| 66 |
+
|
| 67 |
+
if 'results' in st.session_state:
|
| 68 |
+
results = st.session_state.results
|
| 69 |
+
for result in results["feedback"]:
|
| 70 |
+
st.markdown(f"#### TIL: {result['til']}")
|
| 71 |
+
st.markdown(f"**Feedback:** {result['feedback']}")
|
| 72 |
+
if result['feedback'] == "not_ok":
|
| 73 |
+
st.markdown(f"**Criteria:** {result['feedback_criteria']}")
|
| 74 |
+
st.markdown(f"**Reason:** {result['reason']}")
|
| 75 |
+
if result.get('suggestion') is not None:
|
| 76 |
+
st.markdown(f"**Suggestion:** {result['suggestion']}")
|
| 77 |
+
|
| 78 |
+
feedback_key = result['til'].replace(' ', '_')
|
| 79 |
+
feedback_given_key = f"{feedback_key}_feedback_given"
|
| 80 |
+
|
| 81 |
+
if feedback_given_key not in st.session_state:
|
| 82 |
+
st.session_state[feedback_given_key] = False
|
| 83 |
+
|
| 84 |
+
if not st.session_state[feedback_given_key]:
|
| 85 |
+
if st.button("helpful", key=f"helpful_{feedback_key}"):
|
| 86 |
+
give_feedback(feedback_key, True)
|
| 87 |
+
st.session_state[feedback_given_key] = True
|
| 88 |
+
|
| 89 |
+
if st.button("not_helpful", key=f"not_helpful_{feedback_key}"):
|
| 90 |
+
give_feedback(feedback_key, False)
|
| 91 |
+
st.session_state[feedback_given_key] = True
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def give_feedback(feedback_key, is_helpful):
|
| 95 |
+
run_id = st.session_state.run_id
|
| 96 |
+
metric_type = "helpful" if is_helpful else "not_helpful"
|
| 97 |
+
metric_score = 1 if is_helpful else 0
|
| 98 |
+
|
| 99 |
+
feedback_data = Feedback(
|
| 100 |
+
metric_type=metric_type,
|
| 101 |
+
metric_score=metric_score,
|
| 102 |
+
feedback_on=feedback_key.replace('_', ' ').title()
|
| 103 |
+
)
|
| 104 |
+
try:
|
| 105 |
+
TilCrew.post_feedback(run_id, feedback_data)
|
| 106 |
+
st.success("Feedback submitted successfully!")
|
| 107 |
+
except Exception as e:
|
| 108 |
+
st.error(f"Failed to submit feedback: {e}")
|
| 109 |
+
|
| 110 |
+
st.session_state[f"{feedback_key}_feedback_given"] = True
|
| 111 |
+
|
| 112 |
+
def clear_feedback_state(results):
|
| 113 |
+
for key in st.session_state.keys():
|
| 114 |
+
if key.endswith("_feedback_given"):
|
| 115 |
+
st.session_state[key] = False
|
| 116 |
|
| 117 |
if __name__ == "__main__":
|
| 118 |
main()
|
| 119 |
+
|
workflows/utils/feedback.py
CHANGED
|
@@ -2,7 +2,7 @@ from pydantic import BaseModel
|
|
| 2 |
from typing import List, Optional
|
| 3 |
|
| 4 |
class Feedback(BaseModel):
|
| 5 |
-
helpful_score: Optional[float]
|
| 6 |
metric_type: Optional[str]
|
| 7 |
metric_score: Optional[float]
|
| 8 |
feedback_on: Optional[str]
|
|
|
|
| 2 |
from typing import List, Optional
|
| 3 |
|
| 4 |
class Feedback(BaseModel):
|
| 5 |
+
helpful_score: Optional[float]=None
|
| 6 |
metric_type: Optional[str]
|
| 7 |
metric_score: Optional[float]
|
| 8 |
feedback_on: Optional[str]
|