AhmadRollHF commited on
Commit
00ebb97
·
verified ·
1 Parent(s): 0d3f4b0

Document project setup and usage

Browse files

Replace the README stub with implementation-grounded documentation covering the project workflow, prerequisites, configuration, local setup, deployment notes, API behavior where applicable, and troubleshooting.

Files changed (1) hide show
  1. README.md +74 -1
README.md CHANGED
@@ -9,4 +9,77 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ > **Note:** This README was generated with assistance from GPT and should be verified against the current implementation.
13
+
14
+ # Outpaint
15
+
16
+ Outpaint is a small Gradio application that extends an image in one direction with Google's Gemini image-generation model (`gemini-2.5-flash-image`, nicknamed Nano Banana in the UI).
17
+
18
+ The app pads the selected edge with chroma-key green, generates an editable instruction describing which region to fill, sends the padded image and prompt to Gemini, and displays the returned image. A generated result can be reused as the next input for iterative expansion.
19
+
20
+ ## Workflow
21
+
22
+ 1. Upload an image.
23
+ 2. Choose top, bottom, left, or right and select 50–500 pixels of padding.
24
+ 3. Inspect the green padded preview and optionally edit the generated prompt.
25
+ 4. Click **Outpaint with Nano Banana**.
26
+ 5. Optionally click **Reuse Outpainted Image** and repeat in another direction.
27
+
28
+ All image state lives in the Gradio session. The application does not implement persistent storage or a separate HTTP API route.
29
+
30
+ ## Project layout
31
+
32
+ | Path | Purpose |
33
+ | --- | --- |
34
+ | `app.py` | Image padding, Gemini request handling, Gradio UI, and event wiring |
35
+ | `requirements.txt` | Pillow and Google Gen AI SDK dependencies |
36
+ | `README.md` | Hugging Face Space metadata and project documentation |
37
+
38
+ ## Prerequisites
39
+
40
+ - Python 3.10 or newer
41
+ - A Google Gemini API key with access to `gemini-2.5-flash-image`
42
+ - Network access to Google's Generative AI API
43
+
44
+ The hosted Space provides Gradio 5.49.1. Install it explicitly for local development because `requirements.txt` does not list Gradio.
45
+
46
+ ## Configuration
47
+
48
+ | Variable | Required | Purpose |
49
+ | --- | --- | --- |
50
+ | `GEMINI_API_KEY` | Yes | Authenticates `google-genai` requests |
51
+
52
+ The Gemini client is created when `app.py` is imported, so set the variable before starting Python. Never commit API keys.
53
+
54
+ ## Run locally
55
+
56
+ ```bash
57
+ python3 -m venv .venv
58
+ source .venv/bin/activate
59
+ python -m pip install --upgrade pip
60
+ python -m pip install -r requirements.txt
61
+ python -m pip install "gradio==5.49.1"
62
+
63
+ export GEMINI_API_KEY="..."
64
+ python app.py
65
+ ```
66
+
67
+ Open `http://127.0.0.1:7860` and follow the workflow above. The app starts Gradio with debug logging enabled.
68
+
69
+ ## Hugging Face Space notes
70
+
71
+ - Repository: `GFHLabs/Outpaint`
72
+ - SDK: Gradio 5.49.1
73
+ - Entry point: `app.py`
74
+ - Add `GEMINI_API_KEY` under **Settings → Variables and secrets** as a secret.
75
+ - Pushing changes to the Space repository triggers a rebuild/restart.
76
+ - The generated image is returned by the model; the code does not preserve source or output files outside Gradio's temporary handling.
77
+
78
+ ## Troubleshooting
79
+
80
+ - **Authentication or permission error:** confirm `GEMINI_API_KEY` is set before startup and that the key can use `gemini-2.5-flash-image` in the current account/region.
81
+ - **No image is returned:** inspect the runtime logs. When the response contains no inline image data, the app intentionally returns the padded input and labels it as “no result from API.”
82
+ - **Green remains in the result:** make the custom prompt explicitly require the entire green region to be replaced, or reduce the padding and retry.
83
+ - **The extension looks inconsistent:** use a smaller padding amount and describe the expected scene continuation, lighting, perspective, and objects in the custom prompt.
84
+ - **An edit appears to use stale state:** click a direction after uploading or reusing an image; that action refreshes the padded image and direction state.
85
+ - **Local import error for Gradio:** install the metadata-pinned version shown above; it is supplied by Hugging Face but omitted from `requirements.txt`.