Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,67 @@
|
|
|
|
|
| 1 |
import openai
|
|
|
|
| 2 |
import streamlit as st
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
prompt = f"""
|
| 9 |
-
|
| 10 |
|
| 11 |
📌 Profile 1:
|
| 12 |
-
{
|
| 13 |
|
| 14 |
📌 Profile 2:
|
| 15 |
-
{
|
| 16 |
|
| 17 |
-
✉️
|
| 18 |
"""
|
| 19 |
|
| 20 |
-
response =
|
| 21 |
model="gpt-4",
|
| 22 |
messages=[
|
| 23 |
-
{"role": "system", "content": "
|
| 24 |
{"role": "user", "content": prompt}
|
| 25 |
],
|
| 26 |
temperature=0.7,
|
| 27 |
-
max_tokens=
|
| 28 |
)
|
| 29 |
|
| 30 |
return response.choices[0].message.content.strip()
|
| 31 |
|
|
|
|
| 32 |
def main():
|
| 33 |
st.set_page_config(page_title="AI Cold Email Generator", layout="centered")
|
| 34 |
-
st.title("
|
| 35 |
-
st.write("
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
if st.button("🚀 生成邮件"):
|
| 41 |
-
if
|
| 42 |
-
with st.spinner("
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
-
st.warning("
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
main()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import openai
|
| 3 |
+
from openai import OpenAI
|
| 4 |
import streamlit as st
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import pytesseract
|
| 7 |
|
| 8 |
+
# 初始化 OpenAI 客户端
|
| 9 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 10 |
|
| 11 |
+
# OCR识别
|
| 12 |
+
def extract_text_from_image(uploaded_file):
|
| 13 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 14 |
+
text = pytesseract.image_to_string(image)
|
| 15 |
+
return text
|
| 16 |
+
|
| 17 |
+
# 邮件生成函数
|
| 18 |
+
def generate_email(profile1_text, profile2_text):
|
| 19 |
prompt = f"""
|
| 20 |
+
请根据以下两人的 LinkedIn Profile,识别他们的共同点,并撰写一封自然、有礼貌的 Coffee Chat 邀请邮件,避免模板式语言。
|
| 21 |
|
| 22 |
📌 Profile 1:
|
| 23 |
+
{profile1_text}
|
| 24 |
|
| 25 |
📌 Profile 2:
|
| 26 |
+
{profile2_text}
|
| 27 |
|
| 28 |
+
✉️ 请生成邮件:
|
| 29 |
"""
|
| 30 |
|
| 31 |
+
response = client.chat.completions.create(
|
| 32 |
model="gpt-4",
|
| 33 |
messages=[
|
| 34 |
+
{"role": "system", "content": "你是一位专业邮件写作助手,擅长撰写冷邮件。"},
|
| 35 |
{"role": "user", "content": prompt}
|
| 36 |
],
|
| 37 |
temperature=0.7,
|
| 38 |
+
max_tokens=500
|
| 39 |
)
|
| 40 |
|
| 41 |
return response.choices[0].message.content.strip()
|
| 42 |
|
| 43 |
+
# 主界面
|
| 44 |
def main():
|
| 45 |
st.set_page_config(page_title="AI Cold Email Generator", layout="centered")
|
| 46 |
+
st.title("📬 AI Cold Email Generator")
|
| 47 |
+
st.write("上传两张 LinkedIn 截图,AI 自动识别并生成 Coffee Chat 邀请邮件。")
|
| 48 |
|
| 49 |
+
col1, col2 = st.columns(2)
|
| 50 |
+
with col1:
|
| 51 |
+
file1 = st.file_uploader("上传你的 LinkedIn 截图", type=["png", "jpg", "jpeg"], key="profile1")
|
| 52 |
+
with col2:
|
| 53 |
+
file2 = st.file_uploader("上传目标联系人的截图", type=["png", "jpg", "jpeg"], key="profile2")
|
| 54 |
|
| 55 |
if st.button("🚀 生成邮件"):
|
| 56 |
+
if file1 and file2:
|
| 57 |
+
with st.spinner("正在识别和撰写邮件..."):
|
| 58 |
+
profile1_text = extract_text_from_image(file1)
|
| 59 |
+
profile2_text = extract_text_from_image(file2)
|
| 60 |
+
email = generate_email(profile1_text, profile2_text)
|
| 61 |
+
st.success("✅ 邮件生成成功")
|
| 62 |
+
st.text_area("📨 邮件内容", email, height=300)
|
| 63 |
else:
|
| 64 |
+
st.warning("请上传两张截图")
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
main()
|