more information.
Browse files- GEMINI.md +40 -0
- app.py +11 -0
- image.webp +0 -0
GEMINI.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Project Overview
|
| 2 |
+
|
| 3 |
+
This project is a web-based user interface for `rayt`, a Python library that implements the concepts from Peter Shirley's "Ray Tracing in One Weekend" book.
|
| 4 |
+
|
| 5 |
+
The application is built using the Gradio framework, providing an interactive way to generate ray-traced images. It leverages Numba and CUDA for accelerated rendering.
|
| 6 |
+
|
| 7 |
+
**Key Technologies:**
|
| 8 |
+
|
| 9 |
+
* **Python:** The core programming language.
|
| 10 |
+
* **Gradio:** Used to create the web-based UI.
|
| 11 |
+
* **rayt library:** The underlying ray tracing engine.
|
| 12 |
+
* **Numba/CUDA:** For performance-critical rendering calculations.
|
| 13 |
+
* **Pillow (PIL):** For image manipulation.
|
| 14 |
+
|
| 15 |
+
# Building and Running
|
| 16 |
+
|
| 17 |
+
## 1. Installation
|
| 18 |
+
|
| 19 |
+
Install the required Python dependencies using pip:
|
| 20 |
+
|
| 21 |
+
```bash
|
| 22 |
+
pip install -r requirements.txt
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## 2. Running the Application
|
| 26 |
+
|
| 27 |
+
To start the Gradio web server, run the main application file:
|
| 28 |
+
|
| 29 |
+
```bash
|
| 30 |
+
python app.py
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
This will launch a local web server, and you can access the UI in your browser at the address provided in the console (usually `http://127.0.0.1:7860`).
|
| 34 |
+
|
| 35 |
+
# Development Conventions
|
| 36 |
+
|
| 37 |
+
* The main application logic is contained in `app.py`.
|
| 38 |
+
* The core rendering functionality is handled by the `render_image` function, which interacts with the `rayt` library.
|
| 39 |
+
* The user interface is defined declaratively using Gradio's `Blocks` API.
|
| 40 |
+
* The application checks for CUDA availability and falls back to the Numba renderer if a compatible GPU is not found.
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import io
|
| 3 |
import sys
|
| 4 |
from PIL import Image
|
|
@@ -57,6 +58,15 @@ with gr.Blocks() as iface:
|
|
| 57 |
gr.Markdown("# Ray Tracing in One Weekend")
|
| 58 |
gr.Markdown("A Python implementation of the book by Peter Shirley, rendered with Numba.")
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column():
|
| 62 |
image_width = gr.Slider(label="Image Width", minimum=100, maximum=1200, value=300, step=10)
|
|
@@ -66,6 +76,7 @@ with gr.Blocks() as iface:
|
|
| 66 |
render_button = gr.Button("Render Image")
|
| 67 |
with gr.Column():
|
| 68 |
output_image = gr.Image(label="Rendered Image", type="pil")
|
|
|
|
| 69 |
|
| 70 |
render_button.click(
|
| 71 |
fn=render_image,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio import themes as gr_themes
|
| 3 |
import io
|
| 4 |
import sys
|
| 5 |
from PIL import Image
|
|
|
|
| 58 |
gr.Markdown("# Ray Tracing in One Weekend")
|
| 59 |
gr.Markdown("A Python implementation of the book by Peter Shirley, rendered with Numba.")
|
| 60 |
|
| 61 |
+
if cuda.is_available():
|
| 62 |
+
gr.Markdown("CUDA support: **<span style='color: green'>AVAILABLE</span>**. Rendering will be done on the GPU.")
|
| 63 |
+
else:
|
| 64 |
+
gr.Markdown(
|
| 65 |
+
"CUDA support: **<span style='color: red'>NOT AVAILABLE</span>**. Rendering will be done on the CPU. "
|
| 66 |
+
"If you have an NVIDIA GPU, you can clone the project and run it locally. "
|
| 67 |
+
"You can also deploy it to a server with CUDA support for faster rendering."
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
image_width = gr.Slider(label="Image Width", minimum=100, maximum=1200, value=300, step=10)
|
|
|
|
| 76 |
render_button = gr.Button("Render Image")
|
| 77 |
with gr.Column():
|
| 78 |
output_image = gr.Image(label="Rendered Image", type="pil")
|
| 79 |
+
gr.Image(label="Sample Output", value="image.webp")
|
| 80 |
|
| 81 |
render_button.click(
|
| 82 |
fn=render_image,
|
image.webp
ADDED
|