lunarflu HF Staff commited on
Commit
e4554fa
·
1 Parent(s): 08bc79c

revert to dfif 0.2

Browse files
Files changed (1) hide show
  1. app.py +4 -38
app.py CHANGED
@@ -14,13 +14,9 @@ import matplotlib.pyplot as plt
14
  import matplotlib.image as mpimg
15
  import time
16
 
17
- #----------------------------------------------------------------------------------------------------
18
- #async requests (otherwise each new !deepfloydif will add another ~20s until the first output)
19
- import aiohttp
20
 
21
 
22
 
23
-
24
  #todos
25
  #alert
26
 
@@ -29,35 +25,9 @@ jojogan = gradio_client.Client("akhaliq/JoJoGAN")
29
 
30
  #token update
31
  DFIF_TOKEN = os.getenv('DFIF_TOKEN')
32
- #hf_token = DFIF_TOKEN # could clean this up
33
-
34
- #----------------------------------------------------------------------------------------------------
35
- class AsyncGradioClient(gradio_client.Client):
36
-
37
- def __init__(self, hf_token=None):
38
- self.is_live = False
39
- self.hf_token = hf_token
40
- #
41
- async def predict_async(self, *args, api_name=None, fn_index=None):
42
- if api_name is None:
43
- api_name = self.default_api_name
44
- if fn_index is None:
45
- fn_index = self.default_fn_index
46
- url = self.api_url + api_name
47
- headers = {"Authorization": "Bearer " + self.hf_token} if self.hf_token else {}
48
- async with aiohttp.ClientSession() as session:
49
- async with session.post(url, json={"args": args, "fn_index": fn_index}, headers=headers) as response:
50
- response_json = await response.json()
51
- if "error" in response_json:
52
- raise Exception(response_json["error"])
53
- return response_json["output"]
54
- #----------------------------------------------------------------------------------------------------
55
-
56
  #deepfloydif
57
  #df = Client("DeepFloyd/IF") #not reliable at the moment
58
- #df = Client("huggingface-projects/IF", hf_token=DFIF_TOKEN) # testing replace with new async client
59
- df = AsyncGradioClient("huggingface-projects/IF", hf_token=DFIF_TOKEN)
60
-
61
 
62
 
63
  # Set up discord bot
@@ -119,8 +89,7 @@ class MyClient(discord.Client):
119
  # predict(img, model, api_name="/predict") -> output
120
  # im = jojogan.predict(img, model) -> output
121
  # im = jojogan.predict(attachment.url, style) -> output
122
-
123
- #im = await jojogan.predict_async(attachment.url, style) # new async, could test
124
  im = jojogan.predict(attachment.url, style)
125
  await message.reply(f'Here is the {style} version of it', file=discord.File(im))
126
  else:
@@ -155,13 +124,10 @@ class MyClient(discord.Client):
155
  current_time = int(time.time())
156
  random.seed(current_time)
157
  seed = random.randint(1, 10000)
158
-
159
- #stage_1_results, stage_1_param_path, stage_1_result_path = df.predict("gradio written on a wall", "blur", 1,1,7.0, 'smart100',50, api_name="/generate64")
160
  stage_1_results, stage_1_param_path, stage_1_result_path = df.predict("llama", "blur", seed,1,7.0, 'smart100',50, api_name="/generate64")
161
 
162
- stage_1_results, stage_1_param_path, stage_1_result_path = await df.predict_async("llama", "blur", seed,1,7.0, 'smart100',50, api_name="/generate64")
163
-
164
-
165
 
166
  # Assuming stage_1_results contains the path to the directory
167
  png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]
 
14
  import matplotlib.image as mpimg
15
  import time
16
 
 
 
 
17
 
18
 
19
 
 
20
  #todos
21
  #alert
22
 
 
25
 
26
  #token update
27
  DFIF_TOKEN = os.getenv('DFIF_TOKEN')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  #deepfloydif
29
  #df = Client("DeepFloyd/IF") #not reliable at the moment
30
+ df = Client("huggingface-projects/IF", hf_token=DFIF_TOKEN)
 
 
31
 
32
 
33
  # Set up discord bot
 
89
  # predict(img, model, api_name="/predict") -> output
90
  # im = jojogan.predict(img, model) -> output
91
  # im = jojogan.predict(attachment.url, style) -> output
92
+
 
93
  im = jojogan.predict(attachment.url, style)
94
  await message.reply(f'Here is the {style} version of it', file=discord.File(im))
95
  else:
 
124
  current_time = int(time.time())
125
  random.seed(current_time)
126
  seed = random.randint(1, 10000)
127
+
 
128
  stage_1_results, stage_1_param_path, stage_1_result_path = df.predict("llama", "blur", seed,1,7.0, 'smart100',50, api_name="/generate64")
129
 
130
+ #stage_1_results, stage_1_param_path, stage_1_result_path = df.predict("gradio written on a wall", "blur", 1,1,7.0, 'smart100',50, api_name="/generate64")
 
 
131
 
132
  # Assuming stage_1_results contains the path to the directory
133
  png_files = [f for f in os.listdir(stage_1_results) if f.endswith('.png')]