TeddyYao commited on
Commit
6751b85
·
verified ·
1 Parent(s): 9936035

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -62
app.py CHANGED
@@ -1,25 +1,16 @@
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
- import subprocess # ✅ 添加这一行!
8
-
9
- # ✅ 使用默认 tesseract 路径,Hugging Face 会自动识别
10
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
11
 
12
- def extract_text_from_images(uploaded_files):
13
- all_text = ""
14
- for uploaded_file in uploaded_files:
15
- image = Image.open(uploaded_file).convert("RGB")
16
- text = pytesseract.image_to_string(image)
17
- all_text += text + "\n"
18
- return all_text.strip()
19
 
 
20
  def generate_email(profile1_text, profile2_text):
 
21
  prompt = f"""
22
- 根据以下两人的 LinkedIn Profile,提取共同点,并生成封自然、有温度的 Coffee Chat 邀请邮件(避免模板化):
 
23
 
24
  📌 Profile 1:
25
  {profile1_text}
@@ -27,54 +18,39 @@ def generate_email(profile1_text, profile2_text):
27
  📌 Profile 2:
28
  {profile2_text}
29
 
30
- ✉️ 邮件内容下:
 
 
 
 
 
31
  """
32
 
33
- response = client.chat.completions.create(
34
  model="gpt-4",
35
- messages=[
36
- {"role": "system", "content": "你是一位 AI Networking 邮件助手,擅长生成 Coffee Chat 邮件"},
37
- {"role": "user", "content": prompt}
38
- ],
39
  temperature=0.7,
40
- max_tokens=600
41
  )
42
-
43
- return response.choices[0].message.content.strip()
44
-
45
- def main():
46
- st.set_page_config(page_title="AI Cold Email Generator", layout="centered")
47
- st.title("📬 AI Cold Email Generator")
48
- st.write("上传两位 LinkedIn 截图(每人可多张),系统将识别并生成 Coffee Chat 邀请邮件")
49
-
50
- col1, col2 = st.columns(2)
51
- with col1:
52
- files1 = st.file_uploader("上传你的 LinkedIn 截图(支持多张)", type=["png", "jpg", "jpeg"], accept_multiple_files=True, key="profile1")
53
- with col2:
54
- files2 = st.file_uploader("上传目标联系人的截图(支持多张)", type=["png", "jpg", "jpeg"], accept_multiple_files=True, key="profile2")
55
-
56
- if st.button("🚀 生成邮件"):
57
- if files1 and files2:
58
- with st.spinner("识别图像内容 + 生成邮件..."):
59
- profile1_text = extract_text_from_images(files1)
60
- profile2_text = extract_text_from_images(files2)
61
- email = generate_email(profile1_text, profile2_text)
62
- st.success("✅ 邮件生成成功")
63
- st.text_area("📨 Coffee Chat 邮件内容", email, height=300)
64
- else:
65
- st.warning("请上传双方截图")
66
-
67
- import subprocess
68
-
69
- with st.expander("🛠️ 查看 Tesseract 安装状态(调试用)"):
70
- try:
71
- version = subprocess.check_output(["tesseract", "--version"])
72
- st.success("✅ Tesseract 已安装")
73
- st.code(version.decode(), language="bash")
74
- except Exception as e:
75
- st.error("❌ Tesseract 未安装")
76
- st.text(str(e))
77
-
78
-
79
- if __name__ == "__main__":
80
- main()
 
 
1
  import openai
2
+ import os
3
  import streamlit as st
 
 
 
 
 
 
4
 
5
+ # ========== 设置 OpenAI API Key ==========
6
+ client = openai.Client(api_key=os.getenv("OPENAI_API_KEY"))
 
 
 
 
 
7
 
8
+ # ========== 生成个性化邮件的函数 ==========
9
  def generate_email(profile1_text, profile2_text):
10
+ """根据用户输入的 LinkedIn 信息生成个性化邮件"""
11
  prompt = f"""
12
+ 你是 AI 助手,专门帮助职场人士通过电子邮件邀请别人进行 coffee chat。
13
+ 现在有两个人的 LinkedIn 信息,你需要根据以下两个信息生成一封个性化且高质量的 Coffee Chat 邀请邮件:
14
 
15
  📌 Profile 1:
16
  {profile1_text}
 
18
  📌 Profile 2:
19
  {profile2_text}
20
 
21
+ 生成的邮件内容必须具有以特点
22
+ 1. 礼貌、简洁且专业;
23
+ 2. 清楚表达双方的共同点并礼貌地提出邀请;
24
+ 3. 语气亲切自然,避免模板化,内容更具个性化。
25
+
26
+ ✉️ 生成的邮件内容如下:
27
  """
28
 
29
+ response = client.completions.create(
30
  model="gpt-4",
31
+ prompt=prompt,
 
 
 
32
  temperature=0.7,
33
+ max_tokens=350
34
  )
35
+
36
+ return response['choices'][0]['text'].strip()
37
+
38
+ # ========== 页面设计 ==========
39
+ st.set_page_config(page_title="AI Cold Email Generator", layout="centered")
40
+ st.title("📬 AI Cold Email Generator")
41
+
42
+ # ========== 用户输入 LinkedIn 信息 ==========
43
+ st.write("请输入两个人的 LinkedIn 信息,系统将生成个性化的邮件。")
44
+
45
+ profile1_text = st.text_area("输入第一个人的 LinkedIn 信息", height=250)
46
+ profile2_text = st.text_area("输入第二个人的 LinkedIn 信息", height=250)
47
+
48
+ # ========== 生成邮件 ==========
49
+ if st.button("🚀 生成邮件"):
50
+ if profile1_text and profile2_text:
51
+ with st.spinner("正在生成个性化邮件..."):
52
+ email = generate_email(profile1_text, profile2_text)
53
+ st.success("✅ 邮件生成成功!")
54
+ st.text_area("📨 Coffee Chat 邮件内容", email, height=300)
55
+ else:
56
+ st.warning("请完整输入两个人的 LinkedIn 信息。")