forked from cgvr/DeltaVR
153 lines
4.2 KiB
Plaintext
153 lines
4.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "d55eb3ce",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import requests\n",
|
|
"import base64\n",
|
|
"import time"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "77b23cd8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# API endpoint\n",
|
|
"BASE_URL = \"http://127.0.0.1:7960\"\n",
|
|
"\n",
|
|
"def generate_no_preview(image_base64: str):\n",
|
|
" \"\"\"Generate 3D model from a single base64-encoded image without previews.\n",
|
|
" \n",
|
|
" Args:\n",
|
|
" image_base64: Base64 string of the image (without 'data:image/...' prefix)\n",
|
|
" \"\"\"\n",
|
|
" try:\n",
|
|
" # Set generation parameters\n",
|
|
" params = {\n",
|
|
" 'image_base64': image_base64,\n",
|
|
" 'seed': 42,\n",
|
|
" 'ss_guidance_strength': 7.5,\n",
|
|
" 'ss_sampling_steps': 30,\n",
|
|
" 'slat_guidance_strength': 7.5,\n",
|
|
" 'slat_sampling_steps': 30,\n",
|
|
" 'mesh_simplify_ratio': 0.95,\n",
|
|
" 'texture_size': 1024,\n",
|
|
" 'output_format': 'glb'\n",
|
|
" }\n",
|
|
" \n",
|
|
" # Start generation\n",
|
|
" print(\"Starting generation...\")\n",
|
|
" response = requests.post(f\"{BASE_URL}/generate_no_preview\", data=params)\n",
|
|
" print(\"Response status:\", response.status_code)\n",
|
|
" response.raise_for_status()\n",
|
|
" \n",
|
|
" # Poll status until complete\n",
|
|
" while True:\n",
|
|
" status = requests.get(f\"{BASE_URL}/status\").json()\n",
|
|
" print(f\"Progress: {status['progress']}%\")\n",
|
|
" \n",
|
|
" if status['status'] == 'COMPLETE':\n",
|
|
" break\n",
|
|
" elif status['status'] == 'FAILED':\n",
|
|
" raise Exception(f\"Generation failed: {status['message']}\")\n",
|
|
" \n",
|
|
" time.sleep(1)\n",
|
|
" \n",
|
|
" # Download the model\n",
|
|
" print(\"Downloading model...\")\n",
|
|
" response = requests.get(f\"{BASE_URL}/download/model\")\n",
|
|
" response.raise_for_status()\n",
|
|
" print(\"Model downloaded.\")\n",
|
|
" \n",
|
|
" return response.content\n",
|
|
" \n",
|
|
" except Exception as e:\n",
|
|
" print(f\"Error: {str(e)}\")\n",
|
|
" return None"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "eb122295",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def generate_model(image_path, output_path):\n",
|
|
" with open(image_path, 'rb') as image_file:\n",
|
|
" image_data = image_file.read()\n",
|
|
"\n",
|
|
" base64_encoded = base64.b64encode(image_data).decode('utf-8')\n",
|
|
" model = generate_no_preview(base64_encoded)\n",
|
|
" \n",
|
|
" with open(output_path, 'wb') as f:\n",
|
|
" f.write(model)\n",
|
|
" print(f\"Model saved to {output_path}\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "2ce7dfdf",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Starting generation...\n",
|
|
"Response status: 200\n",
|
|
"Progress: 100%\n",
|
|
"Downloading model...\n",
|
|
"Model downloaded.\n",
|
|
"Model saved to test_resources/style_test_3_model.glb\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"\n",
|
|
"image_path = 'test_resources/style_test_3.jpg'\n",
|
|
"output_path = \"test_resources/style_test_3_model.glb\"\n",
|
|
"\n",
|
|
"generate_model(image_path, output_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a1224d13",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.11"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|