measmonysuon commited on
Commit
34dc95a
1 Parent(s): 9342a8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -4,18 +4,16 @@ import os
4
  import logging
5
  import requests
6
  from huggingface_hub import login
 
7
 
8
  webhook_server = os.getenv('webhook_server')
9
  API_TOKEN = os.getenv('ZeroGPU')
10
  BASE_URL = os.getenv('SpaceURL')
 
 
11
 
12
  # Set your token
13
- login(token='API_TOKEN', add_to_git_credential=True)
14
-
15
- # Define your headers including the Authorization with your token
16
- headers = {
17
- "Authorization": f"Bearer {API_TOKEN}"
18
- }
19
 
20
  # Initialize the client for image generation "prithivMLmods/IMAGINEO-4K" "mukaist/DALLE-4K"
21
  client_image = Client("measmonysuon/DALLE-4K")
@@ -38,28 +36,23 @@ def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
38
  full_prompt = f"{prompt}, Canon EOS R5, 4K, Photo-Realistic, appearing photorealistic with super fine details, high resolution, natural look, hyper realistic photography, cinematic lighting, --ar 64:37, --v 6.0, --style raw, --stylize 750"
39
 
40
  try:
41
- response = requests.post(
42
- f"{BASE_URL}/run",
43
- headers=headers,
44
- json={
45
- prompt:full_prompt,
46
- negative_prompt:"(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
47
- use_negative_prompt:True,
48
- style:style,
49
- seed:0,
50
- width:width,
51
- height:height,
52
- guidance_scale:5,
53
- randomize_seed:True
54
- }
55
  )
56
  logger.info("Image generation successful.")
57
- response.raise_for_status()
58
- result = response.json()
59
  return result
60
- except requests.RequestException as e:
61
- print(f"Request exception: {e}")
62
- return None
63
 
64
  def request_otp(user_chat_id):
65
  try:
 
4
  import logging
5
  import requests
6
  from huggingface_hub import login
7
+ from huggingface_hub import whoami
8
 
9
  webhook_server = os.getenv('webhook_server')
10
  API_TOKEN = os.getenv('ZeroGPU')
11
  BASE_URL = os.getenv('SpaceURL')
12
+ # Get user information
13
+ user_info = whoami(token=API_TOKEN)
14
 
15
  # Set your token
16
+ login(token=API_TOKEN, add_to_git_credential=True)
 
 
 
 
 
17
 
18
  # Initialize the client for image generation "prithivMLmods/IMAGINEO-4K" "mukaist/DALLE-4K"
19
  client_image = Client("measmonysuon/DALLE-4K")
 
36
  full_prompt = f"{prompt}, Canon EOS R5, 4K, Photo-Realistic, appearing photorealistic with super fine details, high resolution, natural look, hyper realistic photography, cinematic lighting, --ar 64:37, --v 6.0, --style raw, --stylize 750"
37
 
38
  try:
39
+ result = client_image.predict(
40
+ prompt=full_prompt,
41
+ negative_prompt="(deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
42
+ use_negative_prompt=True,
43
+ style=style,
44
+ seed=0,
45
+ width=width,
46
+ height=height,
47
+ guidance_scale=5,
48
+ randomize_seed=True,
49
+ api_name="/run"
 
 
 
50
  )
51
  logger.info("Image generation successful.")
 
 
52
  return result
53
+ except Exception as e:
54
+ logger.error(f"Error generating image: {e}")
55
+ return Non
56
 
57
  def request_otp(user_chat_id):
58
  try: