TeddyYao commited on
Commit
1ec4f90
·
verified ·
1 Parent(s): da5eb1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -20
app.py CHANGED
@@ -1,50 +1,67 @@
 
1
  import openai
 
2
  import streamlit as st
 
 
3
 
4
- # 设置 OpenAI API 密钥(推荐使用 secrets.toml 或 st.secrets)
5
- openai.api_key = st.secrets["OPENAI_API_KEY"] if "OPENAI_API_KEY" in st.secrets else "sk-..." # ← 改为你自己的 API Key
6
 
7
- def generate_email(profile1, profile2):
 
 
 
 
 
 
 
8
  prompt = f"""
9
- 根据以下两位的 LinkedIn 资料,提取共同点,并写一封自然、有礼貌的 Coffee Chat 邀请邮件。避免模板感,适度专业即可。
10
 
11
  📌 Profile 1:
12
- {profile1}
13
 
14
  📌 Profile 2:
15
- {profile2}
16
 
17
- ✉️ 请生成一封个性化 Coffee Chat 邮件:
18
  """
19
 
20
- response = openai.ChatCompletion.create(
21
  model="gpt-4",
22
  messages=[
23
- {"role": "system", "content": "你是一位专业、友好的冷邮件助手,擅长帮用户写好Coffee Chat邮件。"},
24
  {"role": "user", "content": prompt}
25
  ],
26
  temperature=0.7,
27
- max_tokens=400
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("🤖 AI Networking Email Generator")
35
- st.write("输入两个人的 LinkedIn Profile,生成个性化 Coffee Chat 邀请邮件 ☕")
36
 
37
- profile1 = st.text_area("🧑‍💼 请输入你的 LinkedIn Profile", height=150)
38
- profile2 = st.text_area("🎯 请输入目标联系人的 LinkedIn Profile", height=150)
 
 
 
39
 
40
  if st.button("🚀 生成邮件"):
41
- if profile1 and profile2:
42
- with st.spinner("AI 正在撰写邮件中,请稍候..."):
43
- email = generate_email(profile1, profile2)
44
- st.success("✅ 邮件生成成功!可复制使用:")
45
- st.text_area("📬 Coffee Chat 邮件", email, height=200)
 
 
46
  else:
47
- st.warning("请确保两个 Profile 均已填写!")
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()