-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
131 lines (109 loc) · 4.64 KB
/
app.py
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
import streamlit as st
from PIL import Image
from streamlit_chat import message
from ask_everything_about_me.agent.front_agent import load_front_agent
from ask_everything_about_me.config import settings
from ask_everything_about_me.contact_direct import send_gmail
from ask_everything_about_me.tools import load_tools
tools = load_tools(["get_url", "get_recent_tweet", "search_from_docs"])
agent = load_front_agent(tools)
if "agent" not in st.session_state:
st.session_state["agent"] = agent
if "history" not in st.session_state:
st.session_state.history = []
if "intermediate_state" not in st.session_state:
st.session_state.intermediate_state = []
def st_plot():
st.title("😆 ASK EVERYTHING ABOUT ME! 😆")
st.header("")
image = Image.open("documents/concept_art.png")
st.image(image, caption="Concept art generated by stable-diffusion-2-1")
with st.expander("ℹ️ - About this Bot", expanded=True):
st.write(
f"""
This bot can answer the following on {settings.interviewee_name}
- Show you the URLs that are relevant to you.
- Analyze your tweets and show you what you are interested in these days.
- Answer questions about you from your blog or profile.
I assume this service for not only introduce yourself automatically, but you can use this for a preparation of an interview (for example, for a job hunting interview)
s
You can custom this service only for you if you go [Github](https://github.com/Yongtae723/ask_everything_about_me) and customize it as described in the readme!
If you have question, feel free contact with {settings.interviewee_name} directly using format below.
Or send DM via social media like [LinkedIn](https://www.linkedin.com/in/hwang-yongtae/) .
"""
)
st.markdown("")
st.markdown("")
def generate_answer():
user_message = st.session_state.input_text
st.session_state.history.append({"message": user_message, "is_user": True})
try:
message_bot = st.session_state["agent"](
{"input": user_message, "interviewee_name": settings.interviewee_name}
)
st.session_state.history.append(
{
"message": message_bot["output"],
"is_user": False,
"avatar_style": "miniavs",
},
)
except Exception as e:
st.session_state.history.append(
{
"message": f"Sorry... We have some error to generate response... Please contact {settings.interviewee_name} directly",
"is_user": False,
},
avatar_style="miniavs",
)
st.markdown(
"""
## 📌 Let's Ask!
# """
)
st.text_input(
"Input ( Example : Tell us about more than one hardship you've had to deal with? )",
key="input_text",
on_change=generate_answer,
)
ce, c1, ce, c2, c3 = st.columns([0.07, 5, 0.07, 3, 0.07])
with c1:
message(
f"Hi ! I am bot for {settings.interviewee_name}! What do want to know about me?",
avatar_style="miniavs",
)
for chat in st.session_state.history:
with c1:
message(**chat)
with c2:
st.markdown(
f"""
**📨 If you have question, feel free to contact with {settings.interviewee_name} directly.**
"""
)
subject = st.text_input("Subject")
text = st.text_area("Text", height=250)
mail_address = st.text_input("Your E-mail address")
if st.button("Send"):
if not (subject and text and mail_address):
st.write("Please write text, subtitle and mail_address")
else:
res = send_gmail(subject=subject, body=text, email_address=mail_address)
if res[0]:
st.write(
f"""Thank you for contacting me!
you sent E-mail to {settings.interviewee_name} successfully.
{settings.interviewee_name} will reply to your email as soon as possible."""
)
else:
st.write(res[1])
if __name__ == "__main__":
st.set_page_config(
page_title="Ask Everything About Me",
page_icon="😆",
layout="wide",
)
st_plot()
st.markdown(
"**AI and this Web app are made by [Yongtae](https://www.linkedin.com/in/hwang-yongtae/)**"
)