fantaxy commited on
Commit
d98e648
·
verified ·
1 Parent(s): 8a76dcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -3,6 +3,9 @@ from gradio_client import Client
3
  import os
4
  import logging
5
  import requests
 
 
 
6
 
7
  # 로깅 설정
8
  logging.basicConfig(level=logging.INFO)
@@ -13,10 +16,22 @@ api_client = Client("http://211.233.58.202:7960/")
13
  # Webhook URL
14
  WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY0MDYzMTA0MzE1MjZlNTUzYzUxM2Ei_pc"
15
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def send_to_webhook(prompt, image_url):
17
  payload = {
18
  "prompt": prompt,
19
- "image_url": image_url
20
  }
21
  try:
22
  response = requests.post(WEBHOOK_URL, json=payload)
@@ -45,23 +60,23 @@ def respond(message, seed, randomize_seed, width, height, guidance_scale, num_in
45
  logging.info("API response received: %s", result)
46
 
47
  # 결과 확인 및 처리
48
- if isinstance(result, dict) and 'url' in result:
49
- image_url = result['url']
50
- # Webhook으로 데이터 전송
51
- send_to_webhook(message, image_url)
52
- return image_url
53
- elif isinstance(result, tuple):
54
- logging.error("Unexpected tuple response: %s", result)
55
- image_url = result[0]
56
- # Webhook으로 데이터 전송
57
- send_to_webhook(message, image_url)
58
- return image_url
59
  else:
60
  raise ValueError("Unexpected API response format")
61
  except Exception as e:
62
  logging.error("Error during API request: %s", str(e))
63
  return "Failed to generate image due to an error."
64
 
 
65
  css = """
66
  footer {
67
  visibility: hidden;
@@ -137,5 +152,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
137
  outputs=output_image
138
  )
139
 
 
 
140
  if __name__ == "__main__":
141
  demo.launch()
 
3
  import os
4
  import logging
5
  import requests
6
+ import pyimgur
7
+ from PIL import Image
8
+ import io
9
 
10
  # 로깅 설정
11
  logging.basicConfig(level=logging.INFO)
 
16
  # Webhook URL
17
  WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY0MDYzMTA0MzE1MjZlNTUzYzUxM2Ei_pc"
18
 
19
+ # Imgur 클라이언트 ID
20
+ IMGUR_CLIENT_ID = "여기에_당신의_IMGUR_CLIENT_ID를_입력하세요"
21
+ imgur_client = pyimgur.Imgur(IMGUR_CLIENT_ID)
22
+
23
+ def upload_to_imgur(image_path):
24
+ try:
25
+ uploaded_image = imgur_client.upload_image(image_path, title="Generated Image")
26
+ return uploaded_image.link
27
+ except Exception as e:
28
+ logging.error(f"Failed to upload image to Imgur: {e}")
29
+ return None
30
+
31
  def send_to_webhook(prompt, image_url):
32
  payload = {
33
  "prompt": prompt,
34
+ "image": image_url
35
  }
36
  try:
37
  response = requests.post(WEBHOOK_URL, json=payload)
 
60
  logging.info("API response received: %s", result)
61
 
62
  # 결과 확인 및 처리
63
+ if isinstance(result, tuple) and len(result) >= 1:
64
+ local_image_path = result[0]
65
+ # Imgur에 이미지 업로드
66
+ imgur_url = upload_to_imgur(local_image_path)
67
+ if imgur_url:
68
+ # Webhook으로 데이터 전송
69
+ send_to_webhook(message, imgur_url)
70
+ return Image.open(local_image_path)
71
+ else:
72
+ raise ValueError("Failed to upload image to Imgur")
 
73
  else:
74
  raise ValueError("Unexpected API response format")
75
  except Exception as e:
76
  logging.error("Error during API request: %s", str(e))
77
  return "Failed to generate image due to an error."
78
 
79
+
80
  css = """
81
  footer {
82
  visibility: hidden;
 
152
  outputs=output_image
153
  )
154
 
155
+ # ... (나머지 코드는 그대로 유지)
156
+
157
  if __name__ == "__main__":
158
  demo.launch()