Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,6 @@ from optimum_neuron_export import convert
|
|
8 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
9 |
from apscheduler.schedulers.background import BackgroundScheduler
|
10 |
|
11 |
-
import torch
|
12 |
-
from diffusers import FluxPipeline
|
13 |
-
from optimum.neuron import NeuronFluxPipeline
|
14 |
-
from huggingface_hub.utils import HfHubHTTPError, RepositoryNotFoundError
|
15 |
-
|
16 |
# Define transformer tasks and their categories for coloring
|
17 |
TRANSFORMER_TASKS = {
|
18 |
"auto": {"color": "#6b7280", "category": "Auto"},
|
@@ -132,39 +127,6 @@ def toggle_custom_repo_box(pr_destinations: List[str]):
|
|
132 |
|
133 |
def neuron_export(model_id: str, model_type: str, task_or_pipeline: str,
|
134 |
pr_destinations: List[str], custom_repo_id: str, custom_cache_repo: str, oauth_token: gr.OAuthToken):
|
135 |
-
|
136 |
-
try:
|
137 |
-
# 3. The core test: try to load the model's config using the user's token.
|
138 |
-
# This will fail if the user doesn't have access to the gated repo's files.
|
139 |
-
# pipe = FluxPipeline.from_pretrained(pretrained_model_name_or_path="black-forest-labs/FLUX.1-Krea-dev", torch_dtype=torch.bfloat16, token=oauth_token.token)
|
140 |
-
|
141 |
-
model = NeuronFluxPipeline.from_pretrained(
|
142 |
-
"black-forest-labs/FLUX.1-Krea-dev",
|
143 |
-
export=True,
|
144 |
-
tensor_parallel_size=4,
|
145 |
-
token=oauth_token.token,
|
146 |
-
batch_size=1,
|
147 |
-
sequence_length=128,
|
148 |
-
)
|
149 |
-
|
150 |
-
except RepositoryNotFoundError:
|
151 |
-
# 5. Handle the case where the repository does not exist
|
152 |
-
return f"### <span style='color: red;'>Not Found 🔴</span>\nThe repository **{model_id}** does not exist."
|
153 |
-
|
154 |
-
except HfHubHTTPError as e:
|
155 |
-
# 6. Handle HTTP errors, which typically indicate permission issues for gated models
|
156 |
-
if e.response.status_code in [401, 403]:
|
157 |
-
return f"""
|
158 |
-
### <span style='color: red;'>Access Denied 🔴</span>
|
159 |
-
You do not have permission to download files from **{model_id}**.
|
160 |
-
|
161 |
-
- Please ensure you have accepted the terms and conditions on the model's page.
|
162 |
-
- This might be a private model you don't have access to.
|
163 |
-
- **Status Code:** {e.response.status_code}
|
164 |
-
"""
|
165 |
-
else:
|
166 |
-
return f"### <span style='color: red;'>An Error Occurred 🔴</span>\n**Details:** {str(e)}"
|
167 |
-
|
168 |
|
169 |
log_buffer = ""
|
170 |
def log(msg):
|
@@ -183,7 +145,6 @@ def neuron_export(model_id: str, model_type: str, task_or_pipeline: str,
|
|
183 |
yield log("🚫 Invalid input. Please specify a model name from the hub.")
|
184 |
return
|
185 |
|
186 |
-
yield log(f"token in app is {oauth_token.token}")
|
187 |
try:
|
188 |
api = HfApi(token=oauth_token.token)
|
189 |
# Set custom cache repo as environment variable
|
|
|
8 |
from gradio_huggingfacehub_search import HuggingfaceHubSearch
|
9 |
from apscheduler.schedulers.background import BackgroundScheduler
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
# Define transformer tasks and their categories for coloring
|
12 |
TRANSFORMER_TASKS = {
|
13 |
"auto": {"color": "#6b7280", "category": "Auto"},
|
|
|
127 |
|
128 |
def neuron_export(model_id: str, model_type: str, task_or_pipeline: str,
|
129 |
pr_destinations: List[str], custom_repo_id: str, custom_cache_repo: str, oauth_token: gr.OAuthToken):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
log_buffer = ""
|
132 |
def log(msg):
|
|
|
145 |
yield log("🚫 Invalid input. Please specify a model name from the hub.")
|
146 |
return
|
147 |
|
|
|
148 |
try:
|
149 |
api = HfApi(token=oauth_token.token)
|
150 |
# Set custom cache repo as environment variable
|