dahyedahye commited on
Commit
49ee488
Β·
1 Parent(s): d3db3fc
Files changed (4) hide show
  1. .env +2 -0
  2. Dockerfile +18 -0
  3. app.py +62 -0
  4. requirements.txt +3 -0
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ SMTP_USER=kyowoon.lee1924@gmail.com
2
+ SMTP_PASSWORD=rhwy amyv hdwq pspa
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
17
+
18
+
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import smtplib
4
+ from email.mime.text import MIMEText
5
+ from email.mime.multipart import MIMEMultipart
6
+ from concurrent.futures import ThreadPoolExecutor
7
+ from fastapi import FastAPI, HTTPException, BackgroundTasks
8
+ from fastapi.responses import JSONResponse
9
+ from dotenv import load_dotenv
10
+
11
+ # ꡬ글 λ“œλΌμ΄λΈŒ 링크, μ–΄λ–€ μ–Έμ–΄, 받을 이메일 μ£Όμ†Œ
12
+
13
+ # .env νŒŒμΌμ—μ„œ μ€‘μš”ν•œ ν™˜κ²½ λ³€μˆ˜ λ‘œλ“œ
14
+ load_dotenv()
15
+
16
+ app = FastAPI(
17
+ version="0.0.1",
18
+ servers=[
19
+ {
20
+ "url": "https://leekwoon-email-api.hf.space",
21
+ "description": "email API",
22
+ }
23
+ ],
24
+ )
25
+
26
+ executor = ThreadPoolExecutor(max_workers=3) # μ΅œλŒ€ 3개의 μŠ€λ ˆλ“œλ‘œ 비동기 μž‘μ—… 처리
27
+
28
+
29
+
30
+ def send_email_(to_email: str):
31
+ smtp_server = "smtp.gmail.com"
32
+ smtp_port = 587
33
+ smtp_user = os.getenv("SMTP_USER")
34
+ smtp_password = os.getenv("SMTP_PASSWORD")
35
+
36
+ subject = "[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€."
37
+ body = f"[kyobody - μžλ§‰μƒμ„±] μž‘μ—…μ΄ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.SRT νŒŒμΌμ„ μ²¨λΆ€ν•˜μ—¬ μ „λ‹¬λ“œλ¦½λ‹ˆλ‹€."
38
+
39
+ msg = MIMEMultipart()
40
+ msg["From"] = smtp_user
41
+ msg["To"] = to_email
42
+ msg["Subject"] = subject
43
+
44
+ msg.attach(MIMEText(body, "plain"))
45
+
46
+ with smtplib.SMTP(smtp_server, smtp_port) as server:
47
+ server.starttls()
48
+ server.login(smtp_user, smtp_password)
49
+ server.sendmail(smtp_user, to_email, msg.as_string())
50
+
51
+
52
+ @app.post("/send-email")
53
+ def send_email(email: str, background_tasks: BackgroundTasks):
54
+ try:
55
+ # Schedule the transcription and email sending in the background
56
+ background_tasks.add_task(executor.submit, send_email_, email)
57
+
58
+ # Respond to the client immediately
59
+ return JSONResponse(status_code=202, content={"message": "You will receive an email when it's done."})
60
+
61
+ except Exception as e:
62
+ raise HTTPException(status_code=500, detail=str(e))
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi # FastAPI ν”„λ ˆμž„μ›Œν¬
2
+ uvicorn # FastAPI μ„œλ²„ 싀행을 μœ„ν•œ Uvicorn ASGI μ„œλ²„
3
+ python-dotenv