Commit
Β·
49ee488
1
Parent(s):
d3db3fc
- .env +2 -0
- Dockerfile +18 -0
- app.py +62 -0
- 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
|