Spaces:
Runtime error
Runtime error
File size: 5,431 Bytes
fe5c874 b1c91af 2054a61 c5dd2fe 078e6fe 428cc4d 2054a61 fe5c874 197c0a4 b1c91af fe5c874 c5dd2fe 428cc4d c5dd2fe 428cc4d c5dd2fe 428cc4d c5dd2fe 428cc4d c5dd2fe 428cc4d c5dd2fe 428cc4d 0b9ca3e c5dd2fe 428cc4d c5dd2fe fe5c874 c5dd2fe fe5c874 b1c91af c5dd2fe b1c91af fe5c874 197c0a4 fe5c874 c5dd2fe fe5c874 40283cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import streamlit as st
from writer import write_article, incorporate_feedback, _template, evaluate_post
import hmac
import dspy
from dsp.modules import Claude
import phoenix as px
my_traces = px.Client().get_trace_dataset().save()
px.launch_app(trace=px.TraceDataset.load(my_traces))
def check_password():
"""Returns `True` if the user had the correct password."""
def password_entered():
"""Checks whether a password entered by the user is correct."""
if hmac.compare_digest(st.session_state["password"], st.secrets["password"]):
st.session_state["password_correct"] = True
del st.session_state["password"] # Don't store the password.
else:
st.session_state["password_correct"] = False
# Return True if the password is validated.
if st.session_state.get("password_correct", False):
return True
# Show input for password.
st.text_input(
"Password", type="password", on_change=password_entered, key="password"
)
if "password_correct" in st.session_state:
st.error("😕 Password incorrect")
return False
if not check_password():
st.stop()
st.title("Linkedin shill")
#! I hate this
if "feedback_interface" not in st.session_state:
st.session_state.feedback_interface = 0
st.session_state.content = (
":heart_eyes: **Start writing today with the power of AI** :hugging_face:"
)
with st.container(border=True):
container = st.empty()
with st.container(border=True):
container2 = st.empty()
container.markdown(st.session_state.content)
progress_text = "Operation in progress. Please wait."
with st.container():
feedback_container = st.empty()
with st.sidebar:
lm_choice = st.selectbox(
"Select your language model",
(
"gpt4",
"gpt-4-turbo",
"gpt-3.5-turbo",
"claude3 sonnet",
"claude3 haiku",
"claude3 opus",
# "command-r-plus",
),
)
if lm_choice == "gpt-4-turbo":
lm = dspy.OpenAI(
model="gpt-4-0125-preview",
max_tokens=3800,
api_key=st.secrets["OpenAI"],
)
elif lm_choice == "gpt-3.5-turbo":
lm = dspy.OpenAI(
model="gpt-3.5-turbo",
max_tokens=3800,
api_key=st.secrets["OpenAI"],
)
elif lm_choice == "claude3 sonnet":
lm = Claude(
model="claude-3-sonnet-20240229",
api_key=st.secrets["Claude"],
max_tokens=4096,
)
elif lm_choice == "claude3 haiku":
lm = Claude(
model="claude-3-haiku-20240307",
api_key=st.secrets["Claude"],
max_tokens=4096,
)
elif lm_choice == "claude3 opus":
lm = Claude(
model="claude-3-opus-20240229",
api_key=st.secrets["Claude"],
max_tokens=4096,
)
# elif lm_choice == "command-r-plus":
# lm = LmChoice.command_r_plus
else:
lm = dspy.OpenAI(
model="gpt-4",
max_tokens=3800,
api_key=st.secrets["OpenAI"],
)
with st.form("my_form"):
topic = st.text_input("topic", "Oil future")
template = st.text_area("template", _template, height=600)
purpose = st.text_input("purpose", "Informative")
audience = st.text_input("audience", "Linkedin")
tone_style = st.text_input("tone style", "engaging and informative")
key_points = st.text_input(
"key points", "efficiency, climate change, energy dependance"
)
num_words = st.text_input("number of words", "600")
language = st.text_input("language", "english")
if st.form_submit_button(label="Submit"):
user_inputs = {
"topic": topic,
"template": template,
"purpose": purpose,
"audience": audience,
"tone_style": tone_style,
"key_points": key_points,
"num_words": num_words,
"language": language,
}
bar = 1
with st.status(progress_text) as status:
container.status("Sit back and relax! AI is doing the job for you!")
st.session_state.content = write_article(user_inputs, lm)
st.session_state.feedback_interface = 1
container.markdown(st.session_state.content)
status.update(label="Writing complete!", state="complete")
container2.status("AI is self evaluating!")
evaluation = evaluate_post(st.session_state.content, lm)
status.update(label="Evaluation complete!", state="complete")
container2.markdown(evaluation)
if st.session_state.feedback_interface:
with st.container(border=True):
messages = st.container(height=300)
if feedback := st.chat_input("What do you want to change?"):
messages.chat_message("user").write(feedback)
container.status("Sit back and relax! AI is doing the job for you!")
st.session_state.content = incorporate_feedback(
st.session_state.content,
feedback,
lm,
)
messages.chat_message("ai").write("Done!")
container.markdown(st.session_state.content)
|