SkalskiP commited on
Commit
40b82c8
1 Parent(s): 92f75b1

Revert "test running API calls with user HF_TOKEN"

Browse files

This reverts commit 24aa6b97f1fb8ce9581cd9e40402fd163fc896d3.

Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -1,9 +1,10 @@
1
- import random
2
  from typing import Tuple
3
 
4
- import gradio as gr
5
- import numpy as np
6
  import requests
 
 
 
7
  import spaces
8
  import torch
9
  from PIL import Image, ImageFilter
@@ -22,8 +23,8 @@ MAX_SEED = np.iinfo(np.int32).max
22
  IMAGE_SIZE = 1024
23
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
24
 
25
- # HF_TOKEN = os.environ.get("HF_TOKEN", None)
26
- # client = Client("SkalskiP/florence-sam-masking", hf_token=HF_TOKEN)
27
 
28
 
29
  def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
@@ -43,7 +44,6 @@ def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
43
 
44
  EXAMPLES = [
45
  [
46
- None,
47
  {
48
  "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
49
  "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2.png", stream=True).raw))],
@@ -57,7 +57,6 @@ EXAMPLES = [
57
  30
58
  ],
59
  [
60
- None,
61
  {
62
  "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
63
  "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-3.png", stream=True).raw))],
@@ -102,14 +101,8 @@ def is_image_empty(image: Image.Image) -> bool:
102
  return all(pixel == 0 for pixel in pixels)
103
 
104
 
105
- def set_client_for_session(request: gr.Request):
106
- x_ip_token = request.headers['x-ip-token']
107
- return Client("SkalskiP/florence-sam-masking", headers={"X-IP-Token": x_ip_token})
108
-
109
-
110
  @spaces.GPU(duration=100)
111
  def process(
112
- client,
113
  input_image_editor: dict,
114
  inpainting_prompt_text: str,
115
  masking_prompt_text: str,
@@ -171,7 +164,6 @@ def process(
171
 
172
 
173
  with gr.Blocks() as demo:
174
- client_component = gr.State()
175
  gr.Markdown(MARKDOWN)
176
  with gr.Row():
177
  with gr.Column():
@@ -248,7 +240,6 @@ with gr.Blocks() as demo:
248
  input_image_editor_component,
249
  inpainting_prompt_text_component,
250
  masking_prompt_text_component,
251
- masking_prompt_text_component,
252
  seed_slicer_component,
253
  randomize_seed_checkbox_component,
254
  strength_slider_component,
@@ -278,6 +269,5 @@ with gr.Blocks() as demo:
278
  output_mask_component
279
  ]
280
  )
281
- demo.load(set_client_for_session, None, client_component)
282
 
283
  demo.launch(debug=False, show_error=True)
 
 
1
  from typing import Tuple
2
 
3
+ import os
 
4
  import requests
5
+ import random
6
+ import numpy as np
7
+ import gradio as gr
8
  import spaces
9
  import torch
10
  from PIL import Image, ImageFilter
 
23
  IMAGE_SIZE = 1024
24
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
25
 
26
+ HF_TOKEN = os.environ.get("HF_TOKEN", None)
27
+ client = Client("SkalskiP/florence-sam-masking", hf_token=HF_TOKEN)
28
 
29
 
30
  def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
 
44
 
45
  EXAMPLES = [
46
  [
 
47
  {
48
  "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
49
  "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2.png", stream=True).raw))],
 
57
  30
58
  ],
59
  [
 
60
  {
61
  "background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
62
  "layers": [remove_background(Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-3.png", stream=True).raw))],
 
101
  return all(pixel == 0 for pixel in pixels)
102
 
103
 
 
 
 
 
 
104
  @spaces.GPU(duration=100)
105
  def process(
 
106
  input_image_editor: dict,
107
  inpainting_prompt_text: str,
108
  masking_prompt_text: str,
 
164
 
165
 
166
  with gr.Blocks() as demo:
 
167
  gr.Markdown(MARKDOWN)
168
  with gr.Row():
169
  with gr.Column():
 
240
  input_image_editor_component,
241
  inpainting_prompt_text_component,
242
  masking_prompt_text_component,
 
243
  seed_slicer_component,
244
  randomize_seed_checkbox_component,
245
  strength_slider_component,
 
269
  output_mask_component
270
  ]
271
  )
 
272
 
273
  demo.launch(debug=False, show_error=True)