kingabzpro commited on
Commit
f9dfab2
·
verified ·
1 Parent(s): c70f7dd

Update app/app_savta.py

Browse files
Files changed (1) hide show
  1. app/app_savta.py +8 -7
app/app_savta.py CHANGED
@@ -4,14 +4,15 @@ from pathlib import Path
4
  import torch
5
  from fastai.vision.all import *
6
  import gradio as gr
 
7
 
8
  ######################
9
  # Hugging Face flags #
10
  ######################
11
 
12
  HF_TOKEN = os.getenv("HF_TOKEN")
13
- # `HuggingFaceDatasetSaver` is still available in Gradio ≥ 5
14
- hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "savtadepth-flags-V2")
15
 
16
  ############
17
  # DVC #
@@ -59,7 +60,7 @@ class ImageImageDataLoaders(DataLoaders):
59
 
60
 
61
  def get_y_fn(x: Path) -> Path:
62
- """Map an RGB image path to its depthmap counterpart."""
63
  return Path(str(x).replace(".jpg", "_depth.png"))
64
 
65
 
@@ -92,7 +93,7 @@ learner.load("model")
92
  #####################
93
 
94
  def predict_depth(input_img: PILImage) -> PILImageBW:
95
- """Generate a singlechannel depth prediction from an RGB image."""
96
  depth, *_ = learner.predict(input_img)
97
  return PILImageBW.create(depth).convert("L")
98
 
@@ -105,7 +106,7 @@ title = "SavtaDepth WebApp"
105
  description = (
106
  """
107
  <p style="text-align:center;">
108
- Savta Depth is a collaborative OpenSource project for monocular depth estimation – turn 2‑D photos into 3‑D. 🏞️<br>
109
  Try the model below or explore the resources.
110
  <br><img src="https://huggingface.co/spaces/kingabzpro/savtadepth/resolve/main/examples/cover.png" width="250"/>
111
  </p>
@@ -116,7 +117,7 @@ article = (
116
  """
117
  <p style='text-align:center'>
118
  <a href='https://dagshub.com/OperationSavta/SavtaDepth' target='_blank'>Project on DAGsHub</a> •
119
- <a href='https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?usp=sharing' target='_blank'>Google Colab Demo</a>
120
  <br/>
121
  <img src='https://visitor-badge.glitch.me/badge?page_id=kingabzpro/savtadepth' alt='visitor badge'/>
122
  </p>
@@ -144,7 +145,7 @@ with gr.Blocks(title=title) as demo:
144
  flagging_options=["incorrect", "worst", "ambiguous"],
145
  flagging_callback=hf_writer,
146
  examples=examples,
147
- cache_examples=False, # use live inference for examples
148
  theme=gr.themes.Soft(),
149
  )
150
 
 
4
  import torch
5
  from fastai.vision.all import *
6
  import gradio as gr
7
+ from gradio.flagging import HuggingFaceDatasetSaver
8
 
9
  ######################
10
  # Hugging Face flags #
11
  ######################
12
 
13
  HF_TOKEN = os.getenv("HF_TOKEN")
14
+ # Use the new import path for Gradio ≥ 5
15
+ hf_writer = HuggingFaceDatasetSaver(repo_id="savtadepth-flags-V2", token=HF_TOKEN)
16
 
17
  ############
18
  # DVC #
 
60
 
61
 
62
  def get_y_fn(x: Path) -> Path:
63
+ """Map an RGB image path to its depth-map counterpart."""
64
  return Path(str(x).replace(".jpg", "_depth.png"))
65
 
66
 
 
93
  #####################
94
 
95
  def predict_depth(input_img: PILImage) -> PILImageBW:
96
+ """Generate a single-channel depth prediction from an RGB image."""
97
  depth, *_ = learner.predict(input_img)
98
  return PILImageBW.create(depth).convert("L")
99
 
 
106
  description = (
107
  """
108
  <p style="text-align:center;">
109
+ Savta Depth is a collaborative Open-Source project for monocular depth estimation – turn 2‑D photos into 3‑D.<br>
110
  Try the model below or explore the resources.
111
  <br><img src="https://huggingface.co/spaces/kingabzpro/savtadepth/resolve/main/examples/cover.png" width="250"/>
112
  </p>
 
117
  """
118
  <p style='text-align:center'>
119
  <a href='https://dagshub.com/OperationSavta/SavtaDepth' target='_blank'>Project on DAGsHub</a> •
120
+ <a href='https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?usp=sharing' target='_blank'>Google Colab Demo</a>
121
  <br/>
122
  <img src='https://visitor-badge.glitch.me/badge?page_id=kingabzpro/savtadepth' alt='visitor badge'/>
123
  </p>
 
145
  flagging_options=["incorrect", "worst", "ambiguous"],
146
  flagging_callback=hf_writer,
147
  examples=examples,
148
+ cache_examples=False,
149
  theme=gr.themes.Soft(),
150
  )
151