dev-bjoern commited on
Commit
367770c
ยท
0 Parent(s):

Initial commit: Infinigen Agents Space with HuggingFace Inference API

Browse files
Files changed (3) hide show
  1. README.md +49 -0
  2. app.py +168 -0
  3. requirements.txt +5 -0
README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Infinigen Agents
3
+ emoji: ๐ŸŒ
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 6.0.2
8
+ python_version: "3.10"
9
+ app_file: app.py
10
+ pinned: false
11
+ license: mit
12
+ tags:
13
+ - mcp-server-track
14
+ - agents
15
+ - 3d
16
+ - procedural-generation
17
+ - infinigen
18
+ short_description: "AI Agents for Procedural 3D World Generation"
19
+ ---
20
+
21
+ # ๐ŸŒ Infinigen Agents
22
+
23
+ AI-powered agents for procedural 3D world generation using [Infinigen](https://github.com/princeton-vl/infinigen).
24
+
25
+ ## Features
26
+
27
+ - **Scene Composer**: Compose nature and indoor scenes
28
+ - **Terrain Engineer**: Generate procedural terrain
29
+ - **Asset Generator**: Create creatures, trees, materials
30
+ - **Render Controller**: Manage rendering pipeline
31
+ - **Export Specialist**: Export to various formats
32
+
33
+ ## AI Backend
34
+
35
+ Uses HuggingFace Inference API by default:
36
+ - Model: `openai/gpt-oss-20b`
37
+ - Configurable providers: Cerebras, Together, Nebius, Groq
38
+
39
+ ## MCP Server
40
+
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "infinigen-agents": {
45
+ "url": "https://dev-bjoern-infinigen-agents.hf.space/gradio_api/mcp/sse"
46
+ }
47
+ }
48
+ }
49
+ ```
app.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Infinigen Agents - AI-powered procedural 3D generation
3
+ """
4
+ import os
5
+ import gradio as gr
6
+ from typing import Dict, Any
7
+
8
+ # HuggingFace token from Space secrets
9
+ HF_TOKEN = os.environ.get("HF_TOKEN")
10
+
11
+ # AI Model Configuration
12
+ AI_MODEL = os.environ.get("AI_MODEL", "huggingface")
13
+ HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "openai/gpt-oss-20b")
14
+ HF_PROVIDER = os.environ.get("HF_PROVIDER", None)
15
+
16
+
17
+ def get_model():
18
+ """Get configured AI model for agents."""
19
+ if AI_MODEL == "huggingface":
20
+ from pydantic_ai.models.huggingface import HuggingFaceModel
21
+ from pydantic_ai.providers.huggingface import HuggingFaceProvider
22
+
23
+ provider_kwargs = {"api_key": HF_TOKEN}
24
+ if HF_PROVIDER:
25
+ provider_kwargs["provider_name"] = HF_PROVIDER
26
+
27
+ return HuggingFaceModel(HF_MODEL_ID, provider=HuggingFaceProvider(**provider_kwargs))
28
+ else:
29
+ return f"openai:gpt-4o-mini"
30
+
31
+
32
+ def compose_scene(scene_type: str, seed: int, complexity: str) -> Dict[str, Any]:
33
+ """Compose a scene using AI agent."""
34
+ try:
35
+ from pydantic_ai import Agent
36
+
37
+ agent = Agent(
38
+ get_model(),
39
+ system_prompt=f"""You are a scene composer for Infinigen.
40
+ Create a {complexity} complexity {scene_type} scene with seed {seed}.
41
+ Respond with JSON containing: scene_type, seed, assets, lighting, camera."""
42
+ )
43
+
44
+ result = agent.run_sync(f"Create a {scene_type} scene")
45
+ return {
46
+ "success": True,
47
+ "scene_type": scene_type,
48
+ "seed": seed,
49
+ "complexity": complexity,
50
+ "result": str(result.data)
51
+ }
52
+ except Exception as e:
53
+ return {"success": False, "error": str(e)}
54
+
55
+
56
+ def generate_terrain(terrain_type: str, seed: int, resolution: int) -> Dict[str, Any]:
57
+ """Generate terrain using AI agent."""
58
+ try:
59
+ from pydantic_ai import Agent
60
+
61
+ agent = Agent(
62
+ get_model(),
63
+ system_prompt=f"""You are a terrain engineer for Infinigen.
64
+ Generate {terrain_type} terrain with resolution {resolution}.
65
+ Respond with terrain parameters: heightmap settings, erosion, materials."""
66
+ )
67
+
68
+ result = agent.run_sync(f"Generate {terrain_type} terrain")
69
+ return {
70
+ "success": True,
71
+ "terrain_type": terrain_type,
72
+ "seed": seed,
73
+ "resolution": resolution,
74
+ "result": str(result.data)
75
+ }
76
+ except Exception as e:
77
+ return {"success": False, "error": str(e)}
78
+
79
+
80
+ def get_recommendations(scene_type: str) -> str:
81
+ """Get AI recommendations for scene generation."""
82
+ try:
83
+ from pydantic_ai import Agent
84
+
85
+ agent = Agent(
86
+ get_model(),
87
+ system_prompt="""You are an expert on Infinigen procedural generation.
88
+ Provide recommendations for assets, terrain, lighting, and camera setup."""
89
+ )
90
+
91
+ result = agent.run_sync(f"Recommend settings for a {scene_type} scene in Infinigen")
92
+ return str(result.data)
93
+ except Exception as e:
94
+ return f"Error: {e}"
95
+
96
+
97
+ # Gradio Interface
98
+ with gr.Blocks(title="Infinigen Agents") as demo:
99
+ gr.Markdown("""
100
+ # ๐ŸŒ Infinigen Agents
101
+ **AI-powered procedural 3D world generation**
102
+
103
+ Using HuggingFace Inference API with pydantic-ai
104
+ """)
105
+
106
+ with gr.Tab("Scene Composer"):
107
+ with gr.Row():
108
+ scene_type = gr.Dropdown(
109
+ ["forest", "desert", "mountain", "canyon", "coast", "kitchen", "living_room"],
110
+ label="Scene Type",
111
+ value="forest"
112
+ )
113
+ scene_seed = gr.Number(label="Seed", value=42)
114
+ complexity = gr.Dropdown(["low", "medium", "high"], label="Complexity", value="medium")
115
+
116
+ compose_btn = gr.Button("๐ŸŽฌ Compose Scene", variant="primary")
117
+ scene_output = gr.JSON(label="Scene Result")
118
+
119
+ compose_btn.click(compose_scene, [scene_type, scene_seed, complexity], scene_output)
120
+
121
+ with gr.Tab("Terrain Engineer"):
122
+ with gr.Row():
123
+ terrain_type = gr.Dropdown(
124
+ ["mountain", "canyon", "cliff", "mesa", "river", "volcano", "coast", "plain"],
125
+ label="Terrain Type",
126
+ value="mountain"
127
+ )
128
+ terrain_seed = gr.Number(label="Seed", value=42)
129
+ resolution = gr.Slider(128, 2048, value=512, step=128, label="Resolution")
130
+
131
+ terrain_btn = gr.Button("๐Ÿ”๏ธ Generate Terrain", variant="primary")
132
+ terrain_output = gr.JSON(label="Terrain Result")
133
+
134
+ terrain_btn.click(generate_terrain, [terrain_type, terrain_seed, resolution], terrain_output)
135
+
136
+ with gr.Tab("AI Recommendations"):
137
+ rec_scene_type = gr.Dropdown(
138
+ ["forest", "desert", "mountain", "canyon", "coast"],
139
+ label="Scene Type",
140
+ value="forest"
141
+ )
142
+ rec_btn = gr.Button("๐Ÿ’ก Get Recommendations", variant="primary")
143
+ rec_output = gr.Textbox(label="AI Recommendations", lines=10)
144
+
145
+ rec_btn.click(get_recommendations, rec_scene_type, rec_output)
146
+
147
+ gr.Markdown(f"""
148
+ ---
149
+ ### Configuration
150
+ - **AI Model**: {AI_MODEL}
151
+ - **HF Model**: {HF_MODEL_ID}
152
+ - **Provider**: {HF_PROVIDER or 'auto'}
153
+
154
+ ### MCP Server
155
+ ```json
156
+ {{
157
+ "mcpServers": {{
158
+ "infinigen-agents": {{
159
+ "url": "https://dev-bjoern-infinigen-agents.hf.space/gradio_api/mcp/sse"
160
+ }}
161
+ }}
162
+ }}
163
+ ```
164
+ """)
165
+
166
+
167
+ if __name__ == "__main__":
168
+ demo.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio>=6.0.2
2
+ huggingface_hub>=0.26.0
3
+ pydantic>=2.0.0
4
+ pydantic-ai[huggingface]>=1.0.8
5
+ numpy>=1.26.0