seawolf2357 commited on
Commit
6765e94
ยท
verified ยท
1 Parent(s): efe93ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -17,13 +17,17 @@ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
17
  # ๊ณ ์ •๋œ ๋„ค๊ฑฐํ‹ฐ๋ธŒ ํ”„๋กฌํ”„ํŠธ
18
  negative_prompt = "blur, low quality, bad composition, ugly, disfigured, weird colors, low quality, jpeg artifacts, lowres, grainy, deformed structures, blurry, opaque, low contrast, distorted details, details are low"
19
 
20
- # ์ธํผ๋Ÿฐ์Šค API๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ•จ์ˆ˜
21
  def generate_image(prompt, negative_prompt):
22
  headers = {
23
  "Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
24
  }
25
  data = {
26
- "inputs": prompt + " " + negative_prompt # ํ”„๋กฌํ”„ํŠธ์™€ ๋„ค๊ฑฐํ‹ฐ๋ธŒ ํ”„๋กฌํ”„ํŠธ๋ฅผ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ๊ฒฐํ•ฉ
 
 
 
 
27
  }
28
  api_url = "https://api-inference.huggingface.co/models/fluently/Fluently-XL-Final"
29
  response = requests.post(api_url, headers=headers, json=data)
@@ -34,19 +38,8 @@ def generate_image(prompt, negative_prompt):
34
  logging.error(f"API ์š”์ฒญ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค: {response.text}")
35
  return None
36
 
37
- # ํ”„๋กฌํ”„ํŠธ ๋ฒˆ์—ญ ํ•จ์ˆ˜
38
- def translate_prompt(prompt):
39
- logging.debug(f'ํ”„๋กฌํ”„ํŠธ ๋ฒˆ์—ญ ์ค‘: {prompt}')
40
- translation = translator(prompt, max_length=512)
41
- translated_text = translation[0]['translation_text']
42
- logging.debug(f'๋ฒˆ์—ญ๋œ ํ…์ŠคํŠธ: {translated_text}')
43
- return translated_text
44
-
45
- # ๋””์Šค์ฝ”๋“œ ๋ด‡ ํด๋ž˜์Šค
46
  class MyClient(discord.Client):
47
- async def on_ready(self):
48
- logging.info(f'{self.user}๋กœ ๋กœ๊ทธ์ธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!')
49
-
50
  async def on_message(self, message):
51
  if message.author == self.user:
52
  return
@@ -72,7 +65,7 @@ class MyClient(discord.Client):
72
  # "!image" ๋ช…๋ น์–ด๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ์ „์†ก
73
  await message.channel.send('์˜ฌ๋ฐ”๋ฅธ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. ์˜ˆ) "!image ๊ท€์—ฌ์šด ๊ณ ์–‘์ด๊ฐ€ ์ž ์„ ์ž๊ณ ์žˆ๋‹ค." ๋“ฑ์œผ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.')
74
 
75
- # ๋””์Šค์ฝ”๋“œ ํ† ํฐ ๋ฐ ๋ด‡ ์‹คํ–‰
76
  if __name__ == "__main__":
77
  discord_token = os.getenv('DISCORD_TOKEN')
78
  discord_client = MyClient(intents=intents)
 
17
  # ๊ณ ์ •๋œ ๋„ค๊ฑฐํ‹ฐ๋ธŒ ํ”„๋กฌํ”„ํŠธ
18
  negative_prompt = "blur, low quality, bad composition, ugly, disfigured, weird colors, low quality, jpeg artifacts, lowres, grainy, deformed structures, blurry, opaque, low contrast, distorted details, details are low"
19
 
20
+ # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฐ ์‘๋‹ต ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
21
  def generate_image(prompt, negative_prompt):
22
  headers = {
23
  "Authorization": f"Bearer {os.getenv('HF_TOKEN')}"
24
  }
25
  data = {
26
+ "inputs": {
27
+ "prompt": prompt,
28
+ "negative_prompt": negative_prompt,
29
+ "num_inference_steps": 50
30
+ }
31
  }
32
  api_url = "https://api-inference.huggingface.co/models/fluently/Fluently-XL-Final"
33
  response = requests.post(api_url, headers=headers, json=data)
 
38
  logging.error(f"API ์š”์ฒญ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค: {response.text}")
39
  return None
40
 
41
+ # ๋””์Šค์ฝ”๋“œ ๋ฉ”์‹œ์ง€ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
 
 
 
 
 
 
 
 
42
  class MyClient(discord.Client):
 
 
 
43
  async def on_message(self, message):
44
  if message.author == self.user:
45
  return
 
65
  # "!image" ๋ช…๋ น์–ด๊ฐ€ ์•„๋‹ ๊ฒฝ์šฐ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ์ „์†ก
66
  await message.channel.send('์˜ฌ๋ฐ”๋ฅธ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. ์˜ˆ) "!image ๊ท€์—ฌ์šด ๊ณ ์–‘์ด๊ฐ€ ์ž ์„ ์ž๊ณ ์žˆ๋‹ค." ๋“ฑ์œผ๋กœ ์ž…๋ ฅํ•˜์‹œ๋ฉด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.')
67
 
68
+ # ๋ด‡ ์‹คํ–‰
69
  if __name__ == "__main__":
70
  discord_token = os.getenv('DISCORD_TOKEN')
71
  discord_client = MyClient(intents=intents)