Spaces:
Sleeping
Sleeping
AI Software Factory commited on
Commit Β·
be2dec1
1
Parent(s): 9b549f2
fix: Add GitHub token authentication for Gist creation
Browse filesThe Simple Generator's auto-load DartPad feature requires GitHub authentication:
- Add GITHUB_TOKEN environment variable support
- Update create_anonymous_gist() to use Bearer token auth
- Improve error messages with clear setup instructions
- Add fallback UI when token is not configured
- Document GITHUB_TOKEN setup in README
Without token, users get helpful message explaining how to configure it.
With token, Gist creation works and DartPad auto-loads code.
Setup: Add GITHUB_TOKEN secret in HF Space settings with 'gist' scope.
README.md
CHANGED
|
@@ -20,6 +20,19 @@ Part of the **AI Software Factory** - a complete system that generates Flutter a
|
|
| 20 |
|
| 21 |
This space contains specialized AI agents for design system generation:
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
### AC1: Moodboard Analyzer πΌοΈ β
LIVE
|
| 24 |
- Analyzes reference app screenshots
|
| 25 |
- Extracts color palettes with visual previews
|
|
@@ -191,6 +204,35 @@ HF_TOKEN=your_huggingface_token_here
|
|
| 191 |
|
| 192 |
**Note:** Without the token, agents will use fallback/mock data.
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
## π» Local Development
|
| 195 |
|
| 196 |
```bash
|
|
@@ -213,6 +255,7 @@ The Gradio interface will be available at `http://localhost:7860`
|
|
| 213 |
|
| 214 |
## π§ AI Models Used
|
| 215 |
|
|
|
|
| 216 |
- **Llama 3.2 Vision (11B)** - Image analysis (AC1)
|
| 217 |
- **Llama 3.1 (70B)** - Text generation and synthesis (AC2)
|
| 218 |
- **Llama 3.1 (70B)** - Flutter code planning (AC3)
|
|
|
|
| 20 |
|
| 21 |
This space contains specialized AI agents for design system generation:
|
| 22 |
|
| 23 |
+
### β‘ Simple Generator (NEW!) β
LIVE
|
| 24 |
+
- **Zero-configuration Flutter code generation**
|
| 25 |
+
- Prompt β DeepSeek β Flutter Code β DartPad (auto-loaded!)
|
| 26 |
+
- Automatic GitHub Gist creation for instant DartPad embedding
|
| 27 |
+
- No themes, no presets - just describe what you want
|
| 28 |
+
- Code automatically loaded in DartPad - just click "Run"!
|
| 29 |
+
- Collapsible code viewer for clean UI
|
| 30 |
+
|
| 31 |
+
**Example prompts:**
|
| 32 |
+
- "Create a modern login screen with email and password"
|
| 33 |
+
- "Generate a fitness app home page with statistics cards"
|
| 34 |
+
- "Build a todo list with checkboxes and delete buttons"
|
| 35 |
+
|
| 36 |
### AC1: Moodboard Analyzer πΌοΈ β
LIVE
|
| 37 |
- Analyzes reference app screenshots
|
| 38 |
- Extracts color palettes with visual previews
|
|
|
|
| 204 |
|
| 205 |
**Note:** Without the token, agents will use fallback/mock data.
|
| 206 |
|
| 207 |
+
### GitHub Token (Required for Simple Generator Auto-load DartPad)
|
| 208 |
+
|
| 209 |
+
The **Simple Generator** feature automatically loads generated Flutter code into DartPad by creating GitHub Gists.
|
| 210 |
+
|
| 211 |
+
**Required for:**
|
| 212 |
+
- β‘ Simple Generator β Auto-load code in DartPad
|
| 213 |
+
|
| 214 |
+
**Setup Instructions:**
|
| 215 |
+
|
| 216 |
+
1. Create a GitHub Personal Access Token (classic):
|
| 217 |
+
- Go to [GitHub Settings β Tokens](https://github.com/settings/tokens)
|
| 218 |
+
- Click "Generate new token (classic)"
|
| 219 |
+
- Give it a name like "HF Space Gist Creator"
|
| 220 |
+
- Select scopes: **`gist`** (only this scope is needed)
|
| 221 |
+
- Click "Generate token"
|
| 222 |
+
- **Copy the token** (you won't see it again!)
|
| 223 |
+
|
| 224 |
+
2. Add to `.env` file:
|
| 225 |
+
|
| 226 |
+
```env
|
| 227 |
+
GITHUB_TOKEN=ghp_yourGitHubTokenHere
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
**On HuggingFace Spaces:**
|
| 231 |
+
- Go to Space Settings β Variables
|
| 232 |
+
- Add `GITHUB_TOKEN` as a **secret** (not a public variable!)
|
| 233 |
+
|
| 234 |
+
**Note:** Without this token, the Simple Generator will still work, but users will need to manually copy-paste code into DartPad instead of automatic loading.
|
| 235 |
+
|
| 236 |
## π» Local Development
|
| 237 |
|
| 238 |
```bash
|
|
|
|
| 255 |
|
| 256 |
## π§ AI Models Used
|
| 257 |
|
| 258 |
+
- **DeepSeek Coder** - Direct Flutter code generation (Simple Generator)
|
| 259 |
- **Llama 3.2 Vision (11B)** - Image analysis (AC1)
|
| 260 |
- **Llama 3.1 (70B)** - Text generation and synthesis (AC2)
|
| 261 |
- **Llama 3.1 (70B)** - Flutter code planning (AC3)
|
app.py
CHANGED
|
@@ -776,10 +776,20 @@ def generate_design_themes(
|
|
| 776 |
|
| 777 |
def create_anonymous_gist(code: str, description: str = "Flutter code from AI Software Factory") -> str:
|
| 778 |
"""
|
| 779 |
-
Create
|
| 780 |
Returns the Gist ID for use with DartPad
|
|
|
|
|
|
|
| 781 |
"""
|
| 782 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 783 |
url = "https://api.github.com/gists"
|
| 784 |
payload = {
|
| 785 |
"description": description,
|
|
@@ -793,18 +803,27 @@ def create_anonymous_gist(code: str, description: str = "Flutter code from AI So
|
|
| 793 |
|
| 794 |
headers = {
|
| 795 |
"Accept": "application/vnd.github+json",
|
|
|
|
| 796 |
"X-GitHub-Api-Version": "2022-11-28"
|
| 797 |
}
|
| 798 |
|
|
|
|
| 799 |
response = requests.post(url, json=payload, headers=headers, timeout=10)
|
| 800 |
response.raise_for_status()
|
| 801 |
|
| 802 |
gist_data = response.json()
|
| 803 |
gist_id = gist_data["id"]
|
|
|
|
| 804 |
|
| 805 |
print(f"β
Created Gist: {gist_id}")
|
|
|
|
| 806 |
return gist_id
|
| 807 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
except Exception as e:
|
| 809 |
print(f"β Gist creation failed: {e}")
|
| 810 |
return None
|
|
@@ -871,13 +890,22 @@ def generate_simple_flutter(prompt: str):
|
|
| 871 |
# Fallback - Gist creation failed
|
| 872 |
summary_html = f"""
|
| 873 |
<div style='padding: 20px; background: #fff3cd; border-radius: 8px; border-left: 4px solid #ffc107;'>
|
| 874 |
-
<h3 style='margin: 0 0 10px 0; color: #856404;'>β οΈ Codice Generato (
|
| 875 |
<p style='margin: 5px 0;'><strong>Prompt:</strong> {prompt}</p>
|
| 876 |
<p style='margin: 5px 0;'><strong>Righe di codice:</strong> {lines}</p>
|
| 877 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 878 |
<ol style='margin: 5px 0; padding-left: 20px;'>
|
| 879 |
-
<li>
|
| 880 |
-
<li>
|
|
|
|
| 881 |
<li>Incolla il codice e clicca "Run"</li>
|
| 882 |
</ol>
|
| 883 |
</div>
|
|
|
|
| 776 |
|
| 777 |
def create_anonymous_gist(code: str, description: str = "Flutter code from AI Software Factory") -> str:
|
| 778 |
"""
|
| 779 |
+
Create a GitHub Gist with the generated code
|
| 780 |
Returns the Gist ID for use with DartPad
|
| 781 |
+
|
| 782 |
+
Requires GITHUB_TOKEN environment variable for authentication
|
| 783 |
"""
|
| 784 |
try:
|
| 785 |
+
# Get GitHub token from environment
|
| 786 |
+
github_token = os.getenv("GITHUB_TOKEN", "").strip()
|
| 787 |
+
|
| 788 |
+
if not github_token:
|
| 789 |
+
print("β GITHUB_TOKEN not configured - Gist creation requires authentication")
|
| 790 |
+
print(" Add GITHUB_TOKEN to HuggingFace Space Secrets")
|
| 791 |
+
return None
|
| 792 |
+
|
| 793 |
url = "https://api.github.com/gists"
|
| 794 |
payload = {
|
| 795 |
"description": description,
|
|
|
|
| 803 |
|
| 804 |
headers = {
|
| 805 |
"Accept": "application/vnd.github+json",
|
| 806 |
+
"Authorization": f"Bearer {github_token}",
|
| 807 |
"X-GitHub-Api-Version": "2022-11-28"
|
| 808 |
}
|
| 809 |
|
| 810 |
+
print(f"π€ Creating Gist with GitHub API (authenticated)...")
|
| 811 |
response = requests.post(url, json=payload, headers=headers, timeout=10)
|
| 812 |
response.raise_for_status()
|
| 813 |
|
| 814 |
gist_data = response.json()
|
| 815 |
gist_id = gist_data["id"]
|
| 816 |
+
gist_url = gist_data.get("html_url", f"https://gist.github.com/{gist_id}")
|
| 817 |
|
| 818 |
print(f"β
Created Gist: {gist_id}")
|
| 819 |
+
print(f" URL: {gist_url}")
|
| 820 |
return gist_id
|
| 821 |
|
| 822 |
+
except requests.exceptions.HTTPError as e:
|
| 823 |
+
print(f"β Gist creation failed (HTTP {e.response.status_code}): {e}")
|
| 824 |
+
if e.response.status_code == 401:
|
| 825 |
+
print(" Check that GITHUB_TOKEN is valid and has 'gist' scope")
|
| 826 |
+
return None
|
| 827 |
except Exception as e:
|
| 828 |
print(f"β Gist creation failed: {e}")
|
| 829 |
return None
|
|
|
|
| 890 |
# Fallback - Gist creation failed
|
| 891 |
summary_html = f"""
|
| 892 |
<div style='padding: 20px; background: #fff3cd; border-radius: 8px; border-left: 4px solid #ffc107;'>
|
| 893 |
+
<h3 style='margin: 0 0 10px 0; color: #856404;'>β οΈ Codice Generato (Auto-load DartPad non disponibile)</h3>
|
| 894 |
<p style='margin: 5px 0;'><strong>Prompt:</strong> {prompt}</p>
|
| 895 |
<p style='margin: 5px 0;'><strong>Righe di codice:</strong> {lines}</p>
|
| 896 |
+
<div style='margin: 10px 0; padding: 10px; background: #fff; border-radius: 4px; border-left: 3px solid #ffc107;'>
|
| 897 |
+
<p style='margin: 0 0 5px 0; font-weight: bold; color: #856404;'>βΉοΈ Configurazione richiesta:</p>
|
| 898 |
+
<p style='margin: 5px 0; font-size: 13px;'>Per abilitare il caricamento automatico in DartPad, l'admin dello Space deve:</p>
|
| 899 |
+
<ol style='margin: 5px 0; padding-left: 20px; font-size: 13px;'>
|
| 900 |
+
<li>Creare un GitHub Personal Access Token con scope "gist"</li>
|
| 901 |
+
<li>Aggiungerlo come Secret "GITHUB_TOKEN" nelle impostazioni dello Space</li>
|
| 902 |
+
</ol>
|
| 903 |
+
</div>
|
| 904 |
+
<p style='margin: 10px 0 5px 0; color: #856404; font-weight: bold;'>Come testare manualmente:</p>
|
| 905 |
<ol style='margin: 5px 0; padding-left: 20px;'>
|
| 906 |
+
<li>Espandi la sezione "π» Codice Sorgente" qui sotto</li>
|
| 907 |
+
<li>Copia tutto il codice</li>
|
| 908 |
+
<li>Apri <a href='https://dartpad.dev' target='_blank' style='color: #2563eb;'>dartpad.dev</a> in una nuova tab</li>
|
| 909 |
<li>Incolla il codice e clicca "Run"</li>
|
| 910 |
</ol>
|
| 911 |
</div>
|