fffiloni commited on
Commit
e42dad1
·
verified ·
1 Parent(s): 9b70e6e

update some gradio API calls

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -5,7 +5,7 @@ import json
5
  import re
6
  import random
7
  import numpy as np
8
- from gradio_client import Client
9
  hf_token = os.environ.get("HF_TOKEN")
10
 
11
  MAX_SEED = np.iinfo(np.int32).max
@@ -13,7 +13,7 @@ MAX_SEED = np.iinfo(np.int32).max
13
  def check_api(model_name):
14
  if model_name == "MAGNet":
15
  try :
16
- client = Client("https://fffiloni-magnet.hf.space/")
17
  return "api ready"
18
  except :
19
  return "api not ready yet"
@@ -25,7 +25,7 @@ def check_api(model_name):
25
  return "api not ready yet"
26
  elif model_name == "Riffusion":
27
  try :
28
- client = Client("https://fffiloni-spectrogram-to-music.hf.space/")
29
  return "api ready"
30
  except :
31
  return "api not ready yet"
@@ -69,13 +69,12 @@ def extract_audio(video_in):
69
 
70
 
71
  def get_caption(image_in):
72
- kosmos2_client = Client("https://ydshieh-kosmos-2.hf.space/")
73
  kosmos2_result = kosmos2_client.predict(
74
- image_in, # str (filepath or URL to image) in 'Test Image' Image component
75
- "Detailed", # str in 'Description Type' Radio component
76
- fn_index=4
77
  )
78
-
79
  print(f"KOSMOS2 RETURNS: {kosmos2_result}")
80
 
81
  with open(kosmos2_result[1], 'r') as f:
@@ -121,20 +120,20 @@ def get_caption_from_MD(image_in):
121
 
122
  def get_magnet(prompt):
123
 
124
- client = Client("https://fffiloni-magnet.hf.space/")
125
  result = client.predict(
126
- "facebook/magnet-small-10secs", # Literal['facebook/magnet-small-10secs', 'facebook/magnet-medium-10secs', 'facebook/magnet-small-30secs', 'facebook/magnet-medium-30secs', 'facebook/audio-magnet-small', 'facebook/audio-magnet-medium'] in 'Model' Radio component
127
- "", # str in 'Model Path (custom models)' Textbox component
128
- prompt, # str in 'Input Text' Textbox component
129
- 3, # float in 'Temperature' Number component
130
- 0.9, # float in 'Top-p' Number component
131
- 10, # float in 'Max CFG coefficient' Number component
132
- 1, # float in 'Min CFG coefficient' Number component
133
- 20, # float in 'Decoding Steps (stage 1)' Number component
134
- 10, # float in 'Decoding Steps (stage 2)' Number component
135
- 10, # float in 'Decoding Steps (stage 3)' Number component
136
- 10, # float in 'Decoding Steps (stage 4)' Number component
137
- "prod-stride1 (new!)", # Literal['max-nonoverlap', 'prod-stride1 (new!)'] in 'Span Scoring' Radio component
138
  api_name="/predict_full"
139
  )
140
  print(result)
@@ -157,12 +156,12 @@ def get_audioldm(prompt):
157
  return audio_result
158
 
159
  def get_riffusion(prompt):
160
- client = Client("https://fffiloni-spectrogram-to-music.hf.space/")
161
  result = client.predict(
162
- prompt, # str in 'Musical prompt' Textbox component
163
- "", # str in 'Negative prompt' Textbox component
164
- None, # filepath in 'parameter_4' Audio component
165
- 10, # float (numeric value between 5 and 10) in 'Duration in seconds' Slider component
166
  api_name="/predict"
167
  )
168
  print(result)
 
5
  import re
6
  import random
7
  import numpy as np
8
+ from gradio_client import Client, handle_file
9
  hf_token = os.environ.get("HF_TOKEN")
10
 
11
  MAX_SEED = np.iinfo(np.int32).max
 
13
  def check_api(model_name):
14
  if model_name == "MAGNet":
15
  try :
16
+ client = Client("fffiloni/MAGNet")
17
  return "api ready"
18
  except :
19
  return "api not ready yet"
 
25
  return "api not ready yet"
26
  elif model_name == "Riffusion":
27
  try :
28
+ client = Client("fffiloni/spectrogram-to-music")
29
  return "api ready"
30
  except :
31
  return "api not ready yet"
 
69
 
70
 
71
  def get_caption(image_in):
72
+ kosmos2_client = Client("fffiloni/Kosmos-2-API", hf_token=hf_token)
73
  kosmos2_result = kosmos2_client.predict(
74
+ image_input=handle_file(image_in),
75
+ text_input="Detailed",
76
+ api_name="/generate_predictions"
77
  )
 
78
  print(f"KOSMOS2 RETURNS: {kosmos2_result}")
79
 
80
  with open(kosmos2_result[1], 'r') as f:
 
120
 
121
  def get_magnet(prompt):
122
 
123
+ client = Client("fffiloni/MAGNet")
124
  result = client.predict(
125
+ model="facebook/magnet-small-10secs", # Literal['facebook/magnet-small-10secs', 'facebook/magnet-medium-10secs', 'facebook/magnet-small-30secs', 'facebook/magnet-medium-30secs', 'facebook/audio-magnet-small', 'facebook/audio-magnet-medium'] in 'Model' Radio component
126
+ model_path="", # str in 'Model Path (custom models)' Textbox component
127
+ text=prompt, # str in 'Input Text' Textbox component
128
+ temperature=3, # float in 'Temperature' Number component
129
+ topp=0.9, # float in 'Top-p' Number component
130
+ max_cfg_coef=10, # float in 'Max CFG coefficient' Number component
131
+ min_cfg_coef=1, # float in 'Min CFG coefficient' Number component
132
+ decoding_steps1=20, # float in 'Decoding Steps (stage 1)' Number component
133
+ decoding_steps2=10, # float in 'Decoding Steps (stage 2)' Number component
134
+ decoding_steps3=10, # float in 'Decoding Steps (stage 3)' Number component
135
+ decoding_steps4=10, # float in 'Decoding Steps (stage 4)' Number component
136
+ span_score="prod-stride1 (new!)", # Literal['max-nonoverlap', 'prod-stride1 (new!)'] in 'Span Scoring' Radio component
137
  api_name="/predict_full"
138
  )
139
  print(result)
 
156
  return audio_result
157
 
158
  def get_riffusion(prompt):
159
+ client = Client("fffiloni/spectrogram-to-music")
160
  result = client.predict(
161
+ prompt=prompt, # str in 'Musical prompt' Textbox component
162
+ negative_prompt="", # str in 'Negative prompt' Textbox component
163
+ audio_input=None, # filepath in 'parameter_4' Audio component
164
+ duration=10, # float (numeric value between 5 and 10) in 'Duration in seconds' Slider component
165
  api_name="/predict"
166
  )
167
  print(result)