-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
72 lines (55 loc) · 3.21 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import openai
from flask import Flask, redirect, render_template, request, url_for
import random
import googletrans
app = Flask(__name__)
# key 보안 조심
openai.api_key = os.getenv("OPENAI_API_KEY")
# 번역기 구글 API 사용
translator = googletrans.Translator()
# flask run이라는 명령어를 통해 실행
@app.route("/", methods=("GET", "POST"))
def index():
result = None
funny_word = random.choice(["누구도 날 막지 못해!", "날 선택해줄 줄은 정말 몰랐어", "현명한 선택이야.", "시스템 가동 준비 완료.", "이 사껀은 내가 맡죠.", "상황 파악 끝?", "문도!", "내 솜씨를 제대로 보여줄 시간이군." , "정의의 전장으로" , "니가 사는거라면, 나도 끼지!", "정말 현명한 선택이에요!"])
if request.method == "POST":
image_description = request.form["image_word"]
trans_word = translator.translate(image_description, dest='en')
emoji_word = f'Emphasize the lines and remove the color. cute and very simple messenger emoji like a roughly hand-drawn feel, meaning {trans_word.text}. background color is white. Print it in the center according to the size of the image.'
# 캐리커쳐 느낌의, 대충 손으로 그린 추가하기 -> 별로 재미 없음
# emoji_word = f'Draw simple and hand drawn caricature illustration meaning {trans_word.text}. Emphasize the lines and remove the color. cute and very simple messenger emoticon. background color is white. Print it in the center according to the size of the image.'
# request.form -> 다음과 같은 딕셔너리 형태를 띔, ImmutableMultiDict([('image_word', '강아지')])
print('프린트 :',request.form["image_word"], emoji_word) # 프린트 강아지
response = openai.Image.create(
prompt=emoji_word,
n=1,
size="256x256"
)
# print(response)
result = response.data[0].url
# 의성어 표현 -> 이해가 안되서 노잼
# completion = openai.ChatCompletion.create(
# model="gpt-3.5-turbo",
# messages=[
# {"role": "system", "content": "You are the funniest man and the greatest comedian. Therefore, whatever I say, express it in one funny word. For example: Whoops!, Pungping, Hehe, Mmm"},
# {"role": "user", "content": f'{trans_word}'},
# ]
# )
# trans_word = translator.translate(completion.choices[0].message.content, dest='ko').text
# print(trans_word)
# 분위기에 맞는 컬러 설정 -> 색이 항상 같아서 취소
# 구글 번역 API
# mood_color = openai.Completion.create(
# model="text-davinci-003",
# prompt="The CSS code for a color like a {}:\n\nbackground-color: #".format('cute '+trans_word.text),
# temperature=0,
# max_tokens=64,
# top_p=1.0,
# frequency_penalty=0.0,
# presence_penalty=0.0,
# stop=[";"]
# )
# mood_color = "#"+mood_color.choices[0].text
# print('분위기 색:', mood_color)
return render_template("index.html", result=result, funny_word=funny_word)