Spaces:
Runtime error
Runtime error
Adrien
commited on
Commit
·
b1c91af
1
Parent(s):
ac5421a
add self_eval
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from writer import write_article, incorporate_feedback, _template
|
| 3 |
import hmac
|
| 4 |
import streamlit as st
|
| 5 |
|
|
@@ -44,6 +44,8 @@ if "feedback_interface" not in st.session_state:
|
|
| 44 |
|
| 45 |
with st.container(border=True):
|
| 46 |
container = st.empty()
|
|
|
|
|
|
|
| 47 |
container.markdown(st.session_state.content)
|
| 48 |
|
| 49 |
progress_text = "Operation in progress. Please wait."
|
|
@@ -81,6 +83,10 @@ with st.sidebar:
|
|
| 81 |
st.session_state.feedback_interface = 1
|
| 82 |
container.markdown(st.session_state.content)
|
| 83 |
status.update(label="Writing complete!", state="complete")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
if st.session_state.feedback_interface:
|
| 86 |
with st.container(border=True):
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from writer import write_article, incorporate_feedback, _template, evaluate_post
|
| 3 |
import hmac
|
| 4 |
import streamlit as st
|
| 5 |
|
|
|
|
| 44 |
|
| 45 |
with st.container(border=True):
|
| 46 |
container = st.empty()
|
| 47 |
+
container2 = st.empty()
|
| 48 |
+
|
| 49 |
container.markdown(st.session_state.content)
|
| 50 |
|
| 51 |
progress_text = "Operation in progress. Please wait."
|
|
|
|
| 83 |
st.session_state.feedback_interface = 1
|
| 84 |
container.markdown(st.session_state.content)
|
| 85 |
status.update(label="Writing complete!", state="complete")
|
| 86 |
+
container2.status("AI is self evaluating!")
|
| 87 |
+
evaluation = evaluate_post(st.session_state.content)
|
| 88 |
+
status.update(label="Evaluation complete!", state="complete")
|
| 89 |
+
container2.markdown(evaluation)
|
| 90 |
|
| 91 |
if st.session_state.feedback_interface:
|
| 92 |
with st.container(border=True):
|
writer.py
CHANGED
|
@@ -4,7 +4,7 @@ import streamlit as st
|
|
| 4 |
|
| 5 |
dspy.settings.configure(
|
| 6 |
lm=dspy.OpenAI(
|
| 7 |
-
model="gpt-4
|
| 8 |
max_tokens=4096,
|
| 9 |
api_key=st.secrets["OpenAI"],
|
| 10 |
)
|
|
@@ -132,6 +132,23 @@ class Feedback(Module):
|
|
| 132 |
return corrected_article
|
| 133 |
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
def write_article(user_inputs: dict) -> str:
|
| 136 |
article = LinkedinArticle()
|
| 137 |
content = article.forward(**user_inputs)
|
|
@@ -143,3 +160,7 @@ def incorporate_feedback(original_content, feedback):
|
|
| 143 |
original_content=original_content, feedback=feedback
|
| 144 |
)
|
| 145 |
return refined_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
dspy.settings.configure(
|
| 6 |
lm=dspy.OpenAI(
|
| 7 |
+
model="gpt-4",
|
| 8 |
max_tokens=4096,
|
| 9 |
api_key=st.secrets["OpenAI"],
|
| 10 |
)
|
|
|
|
| 132 |
return corrected_article
|
| 133 |
|
| 134 |
|
| 135 |
+
class Evaluator(dspy.Signature):
|
| 136 |
+
"""You are a creative writing coach, evaluate this linkedin post"""
|
| 137 |
+
|
| 138 |
+
linkedin_post = InputField(prefix="A linkedin post to evaluate")
|
| 139 |
+
output = dspy.OutputField(prefix="A comprehensive evaluation, styled in markdown")
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class SelfEval(Module):
|
| 143 |
+
def __init__(self):
|
| 144 |
+
super().__init__()
|
| 145 |
+
self.self_eval = ChainOfThought(Evaluator)
|
| 146 |
+
|
| 147 |
+
def forward(self, content):
|
| 148 |
+
eval = self.self_eval(content=content).output
|
| 149 |
+
return eval
|
| 150 |
+
|
| 151 |
+
|
| 152 |
def write_article(user_inputs: dict) -> str:
|
| 153 |
article = LinkedinArticle()
|
| 154 |
content = article.forward(**user_inputs)
|
|
|
|
| 160 |
original_content=original_content, feedback=feedback
|
| 161 |
)
|
| 162 |
return refined_content
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def evaluate_post(content: str) -> str:
|
| 166 |
+
return SelfEval().forward(content=content)
|