Spaces:
Running
Running
update create repo for react
Browse files
app.py
CHANGED
|
@@ -775,7 +775,6 @@ def generate(prompt):
|
|
| 775 |
- FP8 quantization requires CUDA compute capability ≥ 9.0 (H200 ✅)
|
| 776 |
- FlashAttention-3 works on H200 hardware via kernels library
|
| 777 |
- Dynamic shapes add flexibility for variable input sizes
|
| 778 |
-
|
| 779 |
## MCP Server Integration
|
| 780 |
|
| 781 |
When the user requests an MCP-enabled Gradio app or asks for tool calling capabilities, you MUST enable MCP server functionality.
|
|
@@ -1573,8 +1572,6 @@ def _ensure_video_dir_exists() -> None:
|
|
| 1573 |
os.makedirs(VIDEO_TEMP_DIR, exist_ok=True)
|
| 1574 |
except Exception:
|
| 1575 |
pass
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
def _register_video_for_session(session_id: str | None, file_path: str) -> None:
|
| 1579 |
if not session_id or not file_path:
|
| 1580 |
return
|
|
@@ -2373,7 +2370,6 @@ AVAILABLE_MODELS = [
|
|
| 2373 |
"description": "MiniMax M2 Free model via OpenRouter for code generation and general tasks"
|
| 2374 |
}
|
| 2375 |
]
|
| 2376 |
-
|
| 2377 |
# Default model selection
|
| 2378 |
DEFAULT_MODEL_NAME = "MiniMax M2 Free"
|
| 2379 |
DEFAULT_MODEL = None
|
|
@@ -3157,7 +3153,6 @@ def parse_react_output(text):
|
|
| 3157 |
def format_svelte_output(files):
|
| 3158 |
"""Format Svelte files into === filename === sections (generic)."""
|
| 3159 |
return format_multipage_output(files)
|
| 3160 |
-
|
| 3161 |
def infer_svelte_dependencies(files: Dict[str, str]) -> Dict[str, str]:
|
| 3162 |
"""Infer npm dependencies from Svelte/TS imports across generated files.
|
| 3163 |
|
|
@@ -3845,7 +3840,6 @@ def generate_image_to_image(input_image_data, prompt: str, token: gr.OAuthToken
|
|
| 3845 |
except Exception as e:
|
| 3846 |
print(f"Image-to-image generation error: {str(e)}")
|
| 3847 |
return f"Error generating image (image-to-image): {str(e)}"
|
| 3848 |
-
|
| 3849 |
def generate_video_from_image(input_image_data, prompt: str, session_id: str | None = None, token: gr.OAuthToken | None = None) -> str:
|
| 3850 |
"""Generate a video from an input image and prompt using Hugging Face InferenceClient.
|
| 3851 |
|
|
@@ -4618,7 +4612,6 @@ def create_image_replacement_blocks(html_content: str, user_prompt: str) -> str:
|
|
| 4618 |
{REPLACE_END}""")
|
| 4619 |
|
| 4620 |
return '\n\n'.join(replacement_blocks)
|
| 4621 |
-
|
| 4622 |
def create_image_replacement_blocks_text_to_image_single(html_content: str, prompt: str) -> str:
|
| 4623 |
"""Create search/replace blocks that generate and insert ONLY ONE text-to-image result.
|
| 4624 |
|
|
@@ -5411,7 +5404,6 @@ def create_multimodal_message(text, image=None):
|
|
| 5411 |
# Keep providers happy: avoid structured multimodal payloads; add a short note instead
|
| 5412 |
# If needed, this can be enhanced per-model with proper multimodal schemas.
|
| 5413 |
return {"role": "user", "content": f"{text}\n\n[An image was provided as reference.]"}
|
| 5414 |
-
|
| 5415 |
def apply_search_replace_changes(original_content: str, changes_text: str) -> str:
|
| 5416 |
"""Apply search/replace changes to content (HTML, Python, etc.)"""
|
| 5417 |
if not changes_text.strip():
|
|
@@ -6192,7 +6184,6 @@ Example format:
|
|
| 6192 |
|
| 6193 |
user_prompt = f"""Existing code:
|
| 6194 |
{last_assistant_msg}
|
| 6195 |
-
|
| 6196 |
Modification instructions:
|
| 6197 |
{query}
|
| 6198 |
|
|
@@ -9308,7 +9299,6 @@ with gr.Blocks(
|
|
| 9308 |
🎨 **Theme saved:** {theme_name}
|
| 9309 |
⚠️ **Restart required** to fully apply the new theme.
|
| 9310 |
**Why restart is needed:** Gradio themes are set during application startup and cannot be changed dynamically at runtime. This ensures all components are properly styled with consistent theming.
|
| 9311 |
-
|
| 9312 |
**To apply your new theme:**
|
| 9313 |
1. Stop the application (Ctrl+C)
|
| 9314 |
2. Restart it with the same command
|
|
@@ -9472,24 +9462,26 @@ with gr.Blocks(
|
|
| 9472 |
# Streamlit/React/docker logic
|
| 9473 |
if sdk == "docker" and language in ["streamlit", "react"]:
|
| 9474 |
try:
|
| 9475 |
-
# For new spaces,
|
| 9476 |
if not is_update:
|
| 9477 |
-
# Use
|
| 9478 |
-
from huggingface_hub import
|
| 9479 |
|
| 9480 |
if language == "react":
|
| 9481 |
-
#
|
| 9482 |
-
|
| 9483 |
-
|
| 9484 |
-
|
|
|
|
| 9485 |
token=token.token,
|
| 9486 |
exist_ok=True
|
| 9487 |
)
|
| 9488 |
else:
|
| 9489 |
-
#
|
| 9490 |
-
|
| 9491 |
-
|
| 9492 |
-
|
|
|
|
| 9493 |
token=token.token,
|
| 9494 |
exist_ok=True
|
| 9495 |
)
|
|
|
|
| 775 |
- FP8 quantization requires CUDA compute capability ≥ 9.0 (H200 ✅)
|
| 776 |
- FlashAttention-3 works on H200 hardware via kernels library
|
| 777 |
- Dynamic shapes add flexibility for variable input sizes
|
|
|
|
| 778 |
## MCP Server Integration
|
| 779 |
|
| 780 |
When the user requests an MCP-enabled Gradio app or asks for tool calling capabilities, you MUST enable MCP server functionality.
|
|
|
|
| 1572 |
os.makedirs(VIDEO_TEMP_DIR, exist_ok=True)
|
| 1573 |
except Exception:
|
| 1574 |
pass
|
|
|
|
|
|
|
| 1575 |
def _register_video_for_session(session_id: str | None, file_path: str) -> None:
|
| 1576 |
if not session_id or not file_path:
|
| 1577 |
return
|
|
|
|
| 2370 |
"description": "MiniMax M2 Free model via OpenRouter for code generation and general tasks"
|
| 2371 |
}
|
| 2372 |
]
|
|
|
|
| 2373 |
# Default model selection
|
| 2374 |
DEFAULT_MODEL_NAME = "MiniMax M2 Free"
|
| 2375 |
DEFAULT_MODEL = None
|
|
|
|
| 3153 |
def format_svelte_output(files):
|
| 3154 |
"""Format Svelte files into === filename === sections (generic)."""
|
| 3155 |
return format_multipage_output(files)
|
|
|
|
| 3156 |
def infer_svelte_dependencies(files: Dict[str, str]) -> Dict[str, str]:
|
| 3157 |
"""Infer npm dependencies from Svelte/TS imports across generated files.
|
| 3158 |
|
|
|
|
| 3840 |
except Exception as e:
|
| 3841 |
print(f"Image-to-image generation error: {str(e)}")
|
| 3842 |
return f"Error generating image (image-to-image): {str(e)}"
|
|
|
|
| 3843 |
def generate_video_from_image(input_image_data, prompt: str, session_id: str | None = None, token: gr.OAuthToken | None = None) -> str:
|
| 3844 |
"""Generate a video from an input image and prompt using Hugging Face InferenceClient.
|
| 3845 |
|
|
|
|
| 4612 |
{REPLACE_END}""")
|
| 4613 |
|
| 4614 |
return '\n\n'.join(replacement_blocks)
|
|
|
|
| 4615 |
def create_image_replacement_blocks_text_to_image_single(html_content: str, prompt: str) -> str:
|
| 4616 |
"""Create search/replace blocks that generate and insert ONLY ONE text-to-image result.
|
| 4617 |
|
|
|
|
| 5404 |
# Keep providers happy: avoid structured multimodal payloads; add a short note instead
|
| 5405 |
# If needed, this can be enhanced per-model with proper multimodal schemas.
|
| 5406 |
return {"role": "user", "content": f"{text}\n\n[An image was provided as reference.]"}
|
|
|
|
| 5407 |
def apply_search_replace_changes(original_content: str, changes_text: str) -> str:
|
| 5408 |
"""Apply search/replace changes to content (HTML, Python, etc.)"""
|
| 5409 |
if not changes_text.strip():
|
|
|
|
| 6184 |
|
| 6185 |
user_prompt = f"""Existing code:
|
| 6186 |
{last_assistant_msg}
|
|
|
|
| 6187 |
Modification instructions:
|
| 6188 |
{query}
|
| 6189 |
|
|
|
|
| 9299 |
🎨 **Theme saved:** {theme_name}
|
| 9300 |
⚠️ **Restart required** to fully apply the new theme.
|
| 9301 |
**Why restart is needed:** Gradio themes are set during application startup and cannot be changed dynamically at runtime. This ensures all components are properly styled with consistent theming.
|
|
|
|
| 9302 |
**To apply your new theme:**
|
| 9303 |
1. Stop the application (Ctrl+C)
|
| 9304 |
2. Restart it with the same command
|
|
|
|
| 9462 |
# Streamlit/React/docker logic
|
| 9463 |
if sdk == "docker" and language in ["streamlit", "react"]:
|
| 9464 |
try:
|
| 9465 |
+
# For new spaces, create a fresh Docker-based space
|
| 9466 |
if not is_update:
|
| 9467 |
+
# Use create_repo to create a new Docker space
|
| 9468 |
+
from huggingface_hub import create_repo
|
| 9469 |
|
| 9470 |
if language == "react":
|
| 9471 |
+
# Create a new React Docker space with docker SDK
|
| 9472 |
+
created_repo = create_repo(
|
| 9473 |
+
repo_id=repo_id,
|
| 9474 |
+
repo_type="space",
|
| 9475 |
+
space_sdk="docker",
|
| 9476 |
token=token.token,
|
| 9477 |
exist_ok=True
|
| 9478 |
)
|
| 9479 |
else:
|
| 9480 |
+
# Create a new Streamlit Docker space
|
| 9481 |
+
created_repo = create_repo(
|
| 9482 |
+
repo_id=repo_id,
|
| 9483 |
+
repo_type="space",
|
| 9484 |
+
space_sdk="docker",
|
| 9485 |
token=token.token,
|
| 9486 |
exist_ok=True
|
| 9487 |
)
|