This is a version of Shap-E: Generating Conditional 3D Implicit Functions, extended with an API in order to serve a Unity demonstration for an haptic device. The unity demonstration allows you to generate a 3D model from a prompt, to load it in unity and to "feel it" through the force feedback of the haptic device.
Generates a single 3D model based on a given text prompt and saves it as an .obj file at a specified path.
| Parameter | Type | Description |
|---|---|---|
| prompt | string | The text prompt to generate the 3D model(s). |
| save_path | string | (Optional) The file path where the model is saved. |
If save_path is not provided, the file will be saved in the default directory where the server is running.
| Parameter | Type | Description |
|---|---|---|
| file_path | string | The path to the generated .obj file. |
200 OK: Request was successful, and 3D models were generated.4XX: Client errors (bad request data).5XX: Server errors (issues with model generation or server configuration).
curl -X POST -H "Content-Type: application/json" -d "{\"prompt\":\"a shark\", \"save_path\":\"C:\\desired\\path\\for\\model\"}" http://localhost:5000/generateusing System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json; // Ensure Newtonsoft.Json is installed: Install-Package Newtonsoft.Json
namespace APIClient
{
class Program
{
static readonly HttpClient client = new HttpClient();
static async Task Main()
{
var url = "http://localhost:5000/generate";
var requestData = new
{
prompt = "a shark",
save_path = "C:\\desired\\path\\for\\model"
};
var json = JsonConvert.SerializeObject(requestData);
var data = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, data);
if(response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Generated model path: " + result);
}
else
{
Console.WriteLine("Error: " + response.StatusCode);
}
}
}
}Here are some highlighted samples from our text-conditional model. For random samples on selected prompts, see samples.md.
|
|
|
|
| A chair that looks like an avocado |
An airplane that looks like a banana |
A spaceship |
|
|
|
|
| A birthday cupcake | A chair that looks like a tree |
A green boot |
|
|
|
|
| A penguin | Ube ice cream cone | A bowl of vegetables |
git clone https://github.com/FARI-brussels/demo-fari-haptic-device-generate3D-backend.git
cd demo-fari-haptic-device-generate3D-backend
pip install -e .
pip install Flask
Note : It is advised to run the code in a conda environement, in windows you may need to use the anaconda terminal
cd shap_e/api
python generate.py
Note : It is advised to run the code in a conda environement