Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
# Brain of the AI (Handling Text, Image, and 3D)
|
| 4 |
+
def ai_process(text_input, image_input, chat_history):
|
| 5 |
+
# History array ko initialize karna
|
| 6 |
+
if chat_history is None:
|
| 7 |
+
chat_history = []
|
| 8 |
+
|
| 9 |
+
user_text = text_input.lower() if text_input else ""
|
| 10 |
+
|
| 11 |
+
# 1. IMAGE-TO-3D LOGIC
|
| 12 |
+
if image_input is not None:
|
| 13 |
+
chat_history.append(("Image uploaded", "Generating 3D model from your image... 🧊"))
|
| 14 |
+
# Jab API connect hogi, toh yahan real 3D file (.glb) ka path aayega
|
| 15 |
+
output_3d_file = "dummy_model.glb"
|
| 16 |
+
return chat_history, output_3d_file
|
| 17 |
+
|
| 18 |
+
# 2. TEXT-TO-3D LOGIC
|
| 19 |
+
elif "3d" in user_text or "render" in user_text:
|
| 20 |
+
chat_history.append((text_input, f"Generating 3D model for '{text_input}'... 🧊"))
|
| 21 |
+
# Same yahan bhi 3D file aayegi
|
| 22 |
+
output_3d_file = "dummy_model.glb"
|
| 23 |
+
return chat_history, output_3d_file
|
| 24 |
+
|
| 25 |
+
# 3. HARD CODING & NORMAL CHAT
|
| 26 |
+
elif text_input:
|
| 27 |
+
reply = f"Logic understood. Here is your code:\n\n```python\nprint('V.O.I.D System Online')\n```"
|
| 28 |
+
chat_history.append((text_input, reply))
|
| 29 |
+
return chat_history, None
|
| 30 |
+
|
| 31 |
+
return chat_history, None
|
| 32 |
+
|
| 33 |
+
# Professional UI Design with gr.Blocks (Yahan se theme hata diya hai)
|
| 34 |
+
with gr.Blocks() as demo:
|
| 35 |
+
gr.Markdown("# 🌌 V.O.I.D - Ultimate AI (Coding + 3D Generation)")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
# Left Side: Chat, Text Input, and Image Upload
|
| 39 |
+
with gr.Column(scale=2):
|
| 40 |
+
chatbot = gr.Chatbot(label="V.O.I.D Terminal", height=400)
|
| 41 |
+
text_input = gr.Textbox(placeholder="Type your prompt here or ask for a 3D model...", label="Text Prompt")
|
| 42 |
+
image_input = gr.Image(type="filepath", label="Upload Image for Image-to-3D (Optional)")
|
| 43 |
+
submit_btn = gr.Button("Generate / Chat 🚀", variant="primary")
|
| 44 |
+
|
| 45 |
+
# Right Side: 3D Model Viewer
|
| 46 |
+
with gr.Column(scale=1):
|
| 47 |
+
model_viewer = gr.Model3D(label="3D Model Viewer (.glb, .obj, .gltf)", height=400)
|
| 48 |
+
|
| 49 |
+
# Button click logic connection
|
| 50 |
+
submit_btn.click(
|
| 51 |
+
fn=ai_process,
|
| 52 |
+
inputs=[text_input, image_input, chatbot],
|
| 53 |
+
outputs=[chatbot, model_viewer]
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Theme ko ab yahan launch() ke andar set kiya hai (Gradio 6.0 fix!)
|
| 57 |
+
demo.launch(theme=gr.themes.Soft())
|