Leyo commited on
Commit
06f88eb
1 Parent(s): d97e4e5
Files changed (1) hide show
  1. app_dialogue.py +3 -37
app_dialogue.py CHANGED
@@ -66,7 +66,6 @@ BAN_TOKENS = ( # For documentation puporse. We are not using this list, it is h
66
  EOS_STRINGS = ["<end_of_utterance>", "\nUser:"]
67
  STOP_SUSPECT_LIST = []
68
 
69
- GRADIO_LINK = "https://huggingfacem4-ai-meme-generator.hf.space"
70
  API_TOKEN = os.getenv("HF_AUTH_TOKEN")
71
  IDEFICS_LOGO = "https://huggingface.co/spaces/HuggingFaceM4/idefics_playground/resolve/main/IDEFICS_logo.png"
72
 
@@ -151,25 +150,6 @@ def choose_gallery(gallery_type: str):
151
  return image_gallery_list
152
 
153
 
154
- # This is a hack to make pre-computing the default examples work.
155
- # During normal inference, we pass images as url to a local file using the method `gradio_link`
156
- # which allows the tgi server to fetch the local image from the frontend server.
157
- # however, we are building the space (and pre-computing is part of building the space), the frontend is not available
158
- # and won't answer. So tgi server will try to fetch an image that is not available yet, which will result in a timeout error
159
- # because tgi will never be able to return the generation.
160
- # To bypass that, we pass instead the images URLs from the spaces repo.
161
- DEFAULT_IMAGES_TMP_PATH_TO_URL = {}
162
- for image_dir in os.listdir("example_images"):
163
- for im_path in os.listdir(f"example_images/{image_dir}"):
164
- H = gr.Image(
165
- f"example_images/{image_dir}/{im_path}", visible=False, type="filepath"
166
- )
167
- tmp_filename = H.preprocess(H.value)
168
- DEFAULT_IMAGES_TMP_PATH_TO_URL[
169
- tmp_filename
170
- ] = f"https://huggingface.co/spaces/HuggingFaceM4/AI_Meme_Generator/resolve/main/example_images/{image_dir}/{im_path}"
171
-
172
-
173
  # Utils to handle the image markdown display logic
174
  def split_str_on_im_markdown(string: str) -> List[str]:
175
  """
@@ -286,12 +266,7 @@ def handle_manual_images_in_user_prompt(user_prompt: str) -> List[str]:
286
  return [user_prompt]
287
 
288
 
289
- def gradio_link(img_path: str) -> str:
290
- url = f"{GRADIO_LINK}/file={img_path}"
291
- return url
292
-
293
-
294
- def prompt_list_to_markdown(prompt_list: List[str], size: int = None) -> str:
295
  """
296
  Convert a user prompt in the list format (i.e. elements are either a PIL image or a string) into
297
  the markdown format that is used for the chatbot history and rendering.
@@ -300,15 +275,9 @@ def prompt_list_to_markdown(prompt_list: List[str], size: int = None) -> str:
300
  for elem in prompt_list:
301
  if is_image(elem):
302
  if is_url(elem):
303
- if size is not None:
304
- resulting_string += f"<img src={elem} width={size} height={size}>"
305
- else:
306
- resulting_string += f"![]({elem})"
307
  else:
308
- if size is not None:
309
- resulting_string += f"<img src='/file={str(elem)}' width='{size}' height={str(size)}>"
310
- else:
311
- resulting_string += f"![](/file={elem})"
312
  else:
313
  resulting_string += elem
314
  return resulting_string
@@ -346,9 +315,6 @@ def remove_spaces_around_token(text: str) -> str:
346
 
347
 
348
  # Chatbot utils
349
- Radio_options_to_font = {}
350
-
351
-
352
  def insert_backslash(string, max_length=50):
353
  # Check if the string length is less than or equal to the max_length
354
  if len(string) <= max_length:
 
66
  EOS_STRINGS = ["<end_of_utterance>", "\nUser:"]
67
  STOP_SUSPECT_LIST = []
68
 
 
69
  API_TOKEN = os.getenv("HF_AUTH_TOKEN")
70
  IDEFICS_LOGO = "https://huggingface.co/spaces/HuggingFaceM4/idefics_playground/resolve/main/IDEFICS_logo.png"
71
 
 
150
  return image_gallery_list
151
 
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  # Utils to handle the image markdown display logic
154
  def split_str_on_im_markdown(string: str) -> List[str]:
155
  """
 
266
  return [user_prompt]
267
 
268
 
269
+ def prompt_list_to_markdown(prompt_list: List[str]) -> str:
 
 
 
 
 
270
  """
271
  Convert a user prompt in the list format (i.e. elements are either a PIL image or a string) into
272
  the markdown format that is used for the chatbot history and rendering.
 
275
  for elem in prompt_list:
276
  if is_image(elem):
277
  if is_url(elem):
278
+ resulting_string += f"![]({elem})"
 
 
 
279
  else:
280
+ resulting_string += f"![](/file={elem})"
 
 
 
281
  else:
282
  resulting_string += elem
283
  return resulting_string
 
315
 
316
 
317
  # Chatbot utils
 
 
 
318
  def insert_backslash(string, max_length=50):
319
  # Check if the string length is less than or equal to the max_length
320
  if len(string) <= max_length: