Spaces:
Paused
Paused
File size: 8,100 Bytes
dfd056d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | #!/usr/bin/env python3
"""
DR-Image-Magic Gradio Interface
A web UI for the Artistic Photo Transform project on Hugging Face Spaces
"""
import gradio as gr
import subprocess
import os
import sys
from pathlib import Path
# Get the project root directory
PROJECT_ROOT = Path(__file__).parent
def run_command(cmd, shell=True):
"""Execute a command and return output"""
try:
result = subprocess.run(
cmd,
shell=shell,
capture_output=True,
text=True,
cwd=PROJECT_ROOT,
timeout=300
)
return result.stdout + result.stderr
except subprocess.TimeoutExpired:
return "β οΈ Command timed out (5 minutes)"
except Exception as e:
return f"β Error: {str(e)}"
def install_dependencies():
"""Install pnpm dependencies"""
return run_command("pnpm install")
def start_dev_server():
"""Start development server"""
return run_command("pnpm run dev", shell=True)
def type_check():
"""Run TypeScript type checking"""
return run_command("pnpm run check")
def format_code():
"""Format code with prettier"""
return run_command("pnpm run format")
def run_tests():
"""Run test suite"""
return run_command("pnpm test")
def push_db_schema():
"""Push database schema"""
return run_command("pnpm run db:push")
def build_production():
"""Build for production"""
return run_command("pnpm run build")
def get_project_info():
"""Get project information"""
info = """
# π¨ Artistic Photo Transform - DR-Image-Magic
## Project Overview
A full-stack application that uses AI to transform photos into artistic variations.
## Tech Stack
- **Frontend**: React 19 + TypeScript + Tailwind CSS
- **Backend**: Express + tRPC + Node.js
- **Database**: MySQL + Drizzle ORM
- **Storage**: AWS S3
- **AI**: Image generation with custom prompts
- **UI Components**: Radix UI + shadcn/ui
- **Testing**: Vitest
## Project Structure
```
βββ client/ # React frontend application
βββ server/ # Express backend server
βββ shared/ # Shared types and utilities
βββ drizzle/ # Database migrations
βββ patches/ # Patch files for dependencies
```
## Key Features
β
Photo upload with drag-and-drop
β
AI-powered image transformations (3 variations)
β
S3 storage for images
β
User authentication & history
β
Transformation gallery view
β
Image download functionality
β
Real-time status updates
β
Responsive design
## Scripts
- `pnpm run dev` - Start development server
- `pnpm run build` - Build for production
- `pnpm start` - Run production server
- `pnpm test` - Run tests
- `pnpm run format` - Format code
- `pnpm run check` - Type checking
- `pnpm run db:push` - Push database schema
"""
return info
def get_setup_guide():
"""Get setup instructions"""
guide = """
# Setup Guide
## Prerequisites
- Node.js 18+
- pnpm package manager
- MySQL database
- AWS S3 account
## Installation Steps
### 1. Install Dependencies
Click the button below to install all required packages:
(Note: This requires pnpm to be installed)
### 2. Environment Variables
Create a `.env` file with:
```
DATABASE_URL=mysql://user:password@localhost:3306/dr_image_magic
AWS_ACCESS_KEY_ID=your_key
AWS_SECRET_ACCESS_KEY=your_secret
AWS_S3_BUCKET=your_bucket
OPENAI_API_KEY=your_openai_key
```
### 3. Database Setup
Run migrations to set up your database:
```bash
pnpm run db:push
```
### 4. Development
Start the development server:
```bash
pnpm run dev
```
The app will be available at `http://localhost:5173`
### 5. Production Deployment
Build the app:
```bash
pnpm run build
```
Start the production server:
```bash
pnpm start
```
"""
return guide
# Create the Gradio interface
with gr.Blocks(title="DR-Image-Magic") as demo:
gr.Markdown("""
# π¨ DR-Image-Magic Dashboard
## Artistic Photo Transform Project Manager
""")
with gr.Tabs():
# Tab 1: Project Info
with gr.Tab("π Project Info"):
project_info = gr.Markdown(get_project_info())
# Tab 2: Setup
with gr.Tab("βοΈ Setup"):
gr.Markdown(get_setup_guide())
with gr.Row():
install_btn = gr.Button("π₯ Install Dependencies", size="lg", variant="primary")
db_btn = gr.Button("ποΈ Push Database Schema", size="lg")
install_output = gr.Textbox(
label="Installation Output",
lines=10,
interactive=False,
placeholder="Click 'Install Dependencies' to start..."
)
db_output = gr.Textbox(
label="Database Push Output",
lines=10,
interactive=False,
placeholder="Click 'Push Database Schema' to start..."
)
install_btn.click(install_dependencies, outputs=install_output)
db_btn.click(push_db_schema, outputs=db_output)
# Tab 3: Development
with gr.Tab("π Development"):
gr.Markdown("""
## Development Tools
Use these tools during development:
- **Type Check**: Verify TypeScript types
- **Format Code**: Auto-format with Prettier
- **Run Tests**: Execute test suite
""")
with gr.Row():
type_check_btn = gr.Button("β Type Check", size="lg", variant="secondary")
format_btn = gr.Button("π Format Code", size="lg", variant="secondary")
test_btn = gr.Button("π§ͺ Run Tests", size="lg", variant="secondary")
with gr.Row():
type_check_output = gr.Textbox(
label="Type Check Results",
lines=8,
interactive=False
)
format_output = gr.Textbox(
label="Format Results",
lines=8,
interactive=False
)
test_output = gr.Textbox(
label="Test Results",
lines=8,
interactive=False
)
type_check_btn.click(type_check, outputs=type_check_output)
format_btn.click(format_code, outputs=format_output)
test_btn.click(run_tests, outputs=test_output)
# Tab 4: Production
with gr.Tab("π¦ Production"):
gr.Markdown("""
## Production Deployment
Build your application for production:
1. Click "Build for Production" to optimize the code
2. Once complete, run `pnpm start` to launch the production server
3. Your app will be available at the server URL
""")
build_btn = gr.Button("ποΈ Build for Production", size="lg", variant="stop")
build_output = gr.Textbox(
label="Build Output",
lines=15,
interactive=False,
placeholder="Click 'Build for Production' to start..."
)
build_btn.click(build_production, outputs=build_output)
gr.Markdown("""
---
## π‘ Tips
- This interface provides a web UI for managing the DR-Image-Magic project
- Most operations require pnpm and Node.js to be installed
- For full development, clone the repository locally
- Check the GitHub repo: [DR-Studios/DR-Image-Magic](https://github.com/DR-Studios/DR-Image-Magic)
""")
if __name__ == "__main__":
demo.launch(share=False, theme=gr.themes.Soft(primary_hue="orange"))
|