File size: 12,132 Bytes
c2b3623
4f0f41b
c2b3623
 
 
 
7a20003
c2b3623
 
f69d4b0
579db2f
c2b3623
 
082d9d1
 
78fc423
082d9d1
78fc423
082d9d1
 
 
78fc423
 
a2a2a54
e2d3712
78fc423
 
 
 
2872dcd
78fc423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2872dcd
 
 
 
 
 
 
 
1418324
 
 
 
 
 
 
 
 
 
 
 
2872dcd
 
 
 
 
 
 
 
1418324
 
 
 
 
 
 
 
 
 
2872dcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78fc423
 
 
 
 
 
 
 
 
 
a2a2a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e2d3712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78fc423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
082d9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78fc423
082d9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
dbf5e27
 
 
 
 
 
082d9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbf5e27
e287280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78fc423
e287280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
---
title: Anycoder
emoji: 🏒
colorFrom: indigo
colorTo: indigo
sdk: gradio
sdk_version: 5.37.0
app_file: app.py
pinned: false
disable_embedding: true
hf_oauth: true
---

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

# AnyCoder - AI Code Generator

AnyCoder is an AI-powered code generator that helps you create applications by describing them in plain English. It supports multiple AI models and can generate HTML/CSS/JavaScript code for web applications.

## Features

- **Multi-Model Support**: Choose from various AI models including DeepSeek, ERNIE-4.5-VL, MiniMax, and Qwen
- **Image-to-Code**: Upload UI design images and get corresponding HTML/CSS code (ERNIE-4.5-VL model)
- **Image Text Extraction**: Upload images and extract text using OCR for processing
- **Website Redesign**: Enter a website URL to extract content and redesign it with modern, responsive layouts
- **Live Preview**: See your generated code in action with the built-in sandbox
- **Web Search Integration**: Enable real-time web search to get the latest information and best practices
- **Chat History**: Keep track of your conversations and generated code
- **Quick Examples**: Pre-built examples to get you started quickly
- **πŸš€ One-Click Deployment**: Deploy your generated applications directly to Hugging Face Spaces

## Installation

1. Clone the repository:
```bash
git clone <repository-url>
cd anycoder
```

2. Install dependencies:
```bash
pip install -r requirements.txt
```

3. Set up environment variables:
```bash
export HF_TOKEN="your_huggingface_token"
export TAVILY_API_KEY="your_tavily_api_key"  # Optional, for web search feature
```

## Usage

1. Run the application:
```bash
python app.py
```

2. Open your browser and navigate to the provided URL

3. Describe your application in the text input field

4. Optionally:
   - Upload a UI design image (for ERNIE-4.5-VL model)
   - Enable web search to get the latest information
   - Choose a different AI model

5. Click "Generate" to create your code

6. View the generated code in the Code Editor tab or see it in action in the Live Preview tab

7. **Deploy to Space**: Enter a title and click "πŸš€ Deploy to Space" to publish your application

## πŸš€ Deployment Feature

AnyCoder now includes one-click deployment to Hugging Face Spaces! This feature allows you to:

### How to Deploy

1. **Login**: Click the "Sign in with Hugging Face" button in the sidebar
2. **Authorize Permissions**: When the authorization page appears, make sure to grant ALL the requested permissions:
   - βœ… **read-repos** - Read access to repositories
   - βœ… **write-repos** - Write access to create repositories
   - βœ… **manage-repos** - Manage repository settings
3. **Complete Authorization**: Click "Authorize" to complete the login
4. **Generate Code**: Generate some HTML code using the AI
5. **Enter Title**: In the sidebar, enter a title for your space (e.g., "My Todo App")
6. **Deploy**: Click the "πŸš€ Deploy to Space" button
7. **Share**: Get a shareable URL for your deployed application

**Important**: You must grant ALL three permissions during the OAuth authorization process. If you only grant partial permissions, deployment will fail.

**Note**: You need to be logged in with your Hugging Face account to deploy. This ensures that:
- Deployments are created under your own account namespace
- You can manage and update your spaces from your Hugging Face dashboard
- Each deployment gets a unique URL under your username

**Technical Note**: The deployment uses your personal OAuth token to create spaces under your account, ensuring full security and ownership of your deployed applications.

### Troubleshooting Deployment Issues

If you encounter permission errors during deployment:

1. **Check Permissions**: Make sure you granted all three required permissions during login
2. **Logout and Login Again**: Click logout and sign in again, ensuring all permissions are granted
3. **Account Status**: Verify your Hugging Face account allows repository creation
4. **Network Issues**: Check your internet connection and try again
5. **Contact Support**: If issues persist, contact Hugging Face support

### What Gets Deployed

- **Complete HTML Application**: Your generated code wrapped in a professional template
- **Responsive Design**: Mobile-friendly layout with modern styling
- **Project Documentation**: README with project details and prompts used
- **Live URL**: Publicly accessible URL that anyone can visit

### Deployment Benefits

- **Instant Publishing**: No need to set up hosting or domains
- **Shareable**: Get a public URL to share with others
- **Professional**: Clean, branded presentation of your work
- **Version Control**: Each deployment creates a new space with timestamp
- **Free Hosting**: Hosted on Hugging Face's infrastructure

### Example Deployment

```
Title: "My Weather Dashboard"
Generated Code: <div>Weather app HTML...</div>
Result: https://huggingface.co/spaces/my-weather-dashboard-1234567890
```

The deployed space will include:
- Your application with professional styling
- A header with your title and AnyCoder branding
- A footer with attribution
- A README documenting the project

## Web Search Feature

The web search feature uses Tavily to provide real-time information when generating code. To enable this feature:

1. Get a free Tavily API key from [Tavily Platform](https://tavily.com/)
2. Set the `TAVILY_API_KEY` environment variable
3. Toggle the "πŸ” Enable Web Search" checkbox in the sidebar

When enabled, the AI will search the web for the latest information, best practices, and technologies related to your request.

## Image Text Extraction

The application supports extracting text from images using OCR (Optical Character Recognition). This feature allows you to:

1. Upload image files (JPG, PNG, BMP, TIFF, GIF, WebP) through the file input
2. Automatically extract text from the images using Tesseract OCR
3. Include the extracted text in your prompts for code generation

### Setting up OCR

To use the image text extraction feature, you need to install Tesseract OCR on your system. See `install_tesseract.md` for detailed installation instructions.

**Example usage:**
- Upload an image containing text (like a screenshot, document, or handwritten notes)
- The application will extract the text and include it in your prompt
- You can then ask the AI to process, summarize, or work with the extracted text

## Website Redesign Feature

The website redesign feature allows you to extract content from existing websites and generate modern, responsive redesigns. This feature:

1. **Extracts Website Content**: Automatically scrapes the target website to extract:
   - Page title and meta description
   - Navigation menu structure
   - Main content sections
   - Images and their descriptions
   - Overall page structure and purpose

2. **Generates Modern Redesigns**: Creates improved versions with:
   - Modern, responsive layouts
   - Enhanced user experience
   - Better accessibility
   - Mobile-first design principles
   - Current design trends and best practices

### How to Use Website Redesign

1. **Enter a Website URL**: In the "🌐 Website URL (for redesign)" field, enter the URL of the website you want to redesign
   - Example: `https://example.com`
   - The URL can be with or without `https://`

2. **Add Custom Requirements**: Optionally describe specific improvements you want:
   - "Make it more modern and minimalist"
   - "Add a dark mode toggle"
   - "Improve the mobile layout"
   - "Use a different color scheme"

3. **Enable Web Search**: Toggle the web search feature to get the latest design trends and best practices

4. **Generate**: Click "Generate" to create your redesigned website

### Example Usage

```
URL: https://example.com
Description: Redesign this website with a modern, minimalist approach. Use a clean typography and improve the mobile experience.
```

The AI will analyze the original website content and create a completely redesigned version that maintains the core functionality while providing a better user experience.

### Supported Websites

The feature works with most public websites, including:
- Business websites
- Portfolio sites
- Blog platforms
- E-commerce sites
- Landing pages
- Documentation sites

**Note**: Some websites may block automated access or require JavaScript to load content. In such cases, the extraction may be limited.

## Available Models

- **DeepSeek V3**: Advanced code generation model
- **DeepSeek R1**: Specialized for code generation tasks
- **ERNIE-4.5-VL**: Multimodal model with image support
- **MiniMax M1**: General-purpose AI model
- **Qwen3-235B-A22B**: Large language model for code generation

## Environment Variables

- `HF_TOKEN`: Your Hugging Face API token (required)
- `TAVILY_API_KEY`: Your Tavily API key (optional, for web search)

## License

[Add your license information here]

## Project Structure

```
anycoder/
β”œβ”€β”€ app.py          # Main application (everything included)
β”œβ”€β”€ app.css         # Basic styling
β”œβ”€β”€ pyproject.toml  # Dependencies
└── README.md       # This file
```

## Setup

1. Set your Hugging Face API token:
   ```bash
   export HF_TOKEN="your_huggingface_token"
   ```

2. Install dependencies:
   ```bash
   uv sync
   ```

3. Run the application:
   ```bash
   uv run python app.py
   ```

## Usage

1. **Sign in with your Hugging Face account** using the login button at the top left.
2. Enter your application requirements in the text area
3. Click "send" to generate code
4. View the generated code in the code drawer
5. See the live preview in the sandbox area
6. Use example cards for quick prompts

## Code Example

```python
import os
from huggingface_hub import InferenceClient

client = InferenceClient(
    provider="novita",
    api_key=os.environ["HF_TOKEN"],
    bill_to="huggingface"
)

completion = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V3-0324",
    messages=[
        {
            "role": "user",
            "content": "Create a simple todo app"
        }
    ],
)
```

## Architecture

The application uses:
- **Gradio**: For the web interface
- **Hugging Face Hub**: For model inference
- **ModelScope Studio**: For UI components
- **OAuth Login**: Requires users to sign in with Hugging Face for code generation
- **Streaming**: For real-time code generation

# Hugging Face Coder

A Gradio-based application that uses Hugging Face models to generate code based on user requirements. The app supports both text-only and multimodal (text + image) code generation.

## Features

- **Multiple Model Support**: DeepSeek V3, DeepSeek R1, and ERNIE-4.5-VL
- **Multimodal Input**: Upload images to help describe your requirements
- **Real-time Code Generation**: Stream responses from the models
- **Live Preview**: See your generated code in action with the built-in sandbox
- **History Management**: Keep track of your previous generations
- **Example Templates**: Quick-start with predefined application templates

## Setup

1. Install dependencies:
```bash
pip install -r requirements.txt
```

2. Set your Hugging Face API token as an environment variable:
```bash
export HF_TOKEN="your_huggingface_token"
```

3. Run the application:
```bash
python app.py
```

## Usage

1. **Text-only Generation**: Simply type your requirements in the text area
2. **Multimodal Generation**: Upload an image and describe what you want to create
3. **Model Selection**: Switch between different models using the model selector
4. **Examples**: Use the provided example templates to get started quickly

## Supported Models

- **DeepSeek V3**: General code generation
- **DeepSeek R1**: Advanced code generation
- **ERNIE-4.5-VL**: Multimodal code generation with image understanding

## Environment Variables

- `HF_TOKEN`: Your Hugging Face API token (required)

## Examples

- Todo App
- Calculator
- Weather Dashboard
- Chat Interface
- E-commerce Product Card
- Login Form
- Dashboard Layout
- Data Table
- Image Gallery
- UI from Image (multimodal)