Spaces:
Running
Running
Upload 4 files
Browse files- docker-space/Dockerfile +38 -0
- docker-space/README.md +42 -0
- docker-space/app.py +410 -0
- docker-space/entrypoint.sh +46 -0
docker-space/Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
# Install system dependencies
|
| 4 |
+
RUN apt-get update && apt-get install -y \
|
| 5 |
+
curl \
|
| 6 |
+
ca-certificates \
|
| 7 |
+
procps \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
+
|
| 10 |
+
# Install Ollama
|
| 11 |
+
RUN curl -fsSL https://ollama.ai/install.sh | sh
|
| 12 |
+
|
| 13 |
+
# Install Python packages
|
| 14 |
+
RUN pip install --no-cache-dir \
|
| 15 |
+
gradio>=4.0.0 \
|
| 16 |
+
requests
|
| 17 |
+
|
| 18 |
+
# Create non-root user (required for HF Spaces)
|
| 19 |
+
RUN useradd -m -u 1000 user
|
| 20 |
+
USER user
|
| 21 |
+
|
| 22 |
+
ENV HOME=/home/user
|
| 23 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 24 |
+
ENV OLLAMA_HOST=0.0.0.0
|
| 25 |
+
ENV OLLAMA_MODELS=/home/user/.ollama/models
|
| 26 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 27 |
+
ENV GRADIO_SERVER_PORT=7860
|
| 28 |
+
|
| 29 |
+
WORKDIR $HOME/app
|
| 30 |
+
|
| 31 |
+
# Copy application files
|
| 32 |
+
COPY --chown=user . $HOME/app
|
| 33 |
+
|
| 34 |
+
RUN chmod +x entrypoint.sh
|
| 35 |
+
|
| 36 |
+
EXPOSE 7860 11434
|
| 37 |
+
|
| 38 |
+
CMD ["./entrypoint.sh"]
|
docker-space/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: GOD Coding Machine
|
| 3 |
+
emoji: 🔥
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# 🔥 FREE GOD Coding Machine - Docker Edition
|
| 12 |
+
|
| 13 |
+
**Ollama running LOCALLY** on HuggingFace Spaces - No rate limits!
|
| 14 |
+
|
| 15 |
+
## 🚀 Features
|
| 16 |
+
|
| 17 |
+
- 💬 **Chat** - Code conversations
|
| 18 |
+
- ⚡ **Generate** - Describe → Get code
|
| 19 |
+
- 🔍 **Explain** - Understand any code
|
| 20 |
+
- 🔧 **Fix** - Debug errors
|
| 21 |
+
- 📝 **Review** - Code reviews
|
| 22 |
+
|
| 23 |
+
## 🤖 Models (Running Locally!)
|
| 24 |
+
|
| 25 |
+
| Model | Size | Speed |
|
| 26 |
+
|-------|------|-------|
|
| 27 |
+
| **Qwen2.5-Coder 7B** | 7B | ~10-15 tok/s |
|
| 28 |
+
| **Qwen2.5-Coder 3B** | 3B | ~20-25 tok/s |
|
| 29 |
+
|
| 30 |
+
## ⚡ Advantages over API Version
|
| 31 |
+
|
| 32 |
+
- ✅ **No rate limits** - Use as much as you want
|
| 33 |
+
- ✅ **Faster responses** - No API latency
|
| 34 |
+
- ✅ **Full privacy** - Code stays on this server
|
| 35 |
+
- ✅ **Consistent** - Always available
|
| 36 |
+
|
| 37 |
+
## 💰 Cost
|
| 38 |
+
|
| 39 |
+
**$0** - Completely free!
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
Built with Ollama + Gradio on HuggingFace Spaces
|
docker-space/app.py
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
🔥 GOD Coding Machine - Docker Edition
|
| 3 |
+
Runs Ollama locally on HuggingFace Spaces
|
| 4 |
+
No rate limits! Full power!
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
import requests
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
OLLAMA_URL = "http://localhost:11434"
|
| 12 |
+
|
| 13 |
+
# Models available (pulled in entrypoint.sh)
|
| 14 |
+
MODELS = {
|
| 15 |
+
"Qwen2.5-Coder 7B (Best)": "qwen2.5-coder:7b",
|
| 16 |
+
"Qwen2.5-Coder 3B (Fast)": "qwen2.5-coder:3b",
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def check_ollama():
|
| 20 |
+
"""Check if Ollama is running"""
|
| 21 |
+
try:
|
| 22 |
+
r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=5)
|
| 23 |
+
return r.status_code == 200
|
| 24 |
+
except:
|
| 25 |
+
return False
|
| 26 |
+
|
| 27 |
+
def get_models():
|
| 28 |
+
"""Get available models from Ollama"""
|
| 29 |
+
try:
|
| 30 |
+
r = requests.get(f"{OLLAMA_URL}/api/tags", timeout=5)
|
| 31 |
+
if r.status_code == 200:
|
| 32 |
+
models = r.json().get("models", [])
|
| 33 |
+
return {m["name"]: m["name"] for m in models}
|
| 34 |
+
except:
|
| 35 |
+
pass
|
| 36 |
+
return MODELS
|
| 37 |
+
|
| 38 |
+
def chat_stream(message: str, history: list, model_name: str, temperature: float, max_tokens: int):
|
| 39 |
+
"""Stream chat responses"""
|
| 40 |
+
|
| 41 |
+
if not check_ollama():
|
| 42 |
+
yield "⏳ Ollama is starting up... please wait 30 seconds and try again."
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
model = MODELS.get(model_name, "qwen2.5-coder:7b")
|
| 46 |
+
|
| 47 |
+
# Build messages
|
| 48 |
+
messages = [
|
| 49 |
+
{
|
| 50 |
+
"role": "system",
|
| 51 |
+
"content": """You are an expert coding assistant. You help with:
|
| 52 |
+
- Writing clean, efficient, well-documented code
|
| 53 |
+
- Debugging and fixing issues
|
| 54 |
+
- Explaining code and programming concepts
|
| 55 |
+
- Code reviews and best practices
|
| 56 |
+
|
| 57 |
+
Always provide code in markdown code blocks with the language specified."""
|
| 58 |
+
}
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
for user_msg, assistant_msg in history:
|
| 62 |
+
messages.append({"role": "user", "content": user_msg})
|
| 63 |
+
if assistant_msg:
|
| 64 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
| 65 |
+
|
| 66 |
+
messages.append({"role": "user", "content": message})
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
response = requests.post(
|
| 70 |
+
f"{OLLAMA_URL}/api/chat",
|
| 71 |
+
json={
|
| 72 |
+
"model": model,
|
| 73 |
+
"messages": messages,
|
| 74 |
+
"stream": True,
|
| 75 |
+
"options": {
|
| 76 |
+
"temperature": temperature,
|
| 77 |
+
"num_predict": max_tokens
|
| 78 |
+
}
|
| 79 |
+
},
|
| 80 |
+
stream=True,
|
| 81 |
+
timeout=300
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
full_response = ""
|
| 85 |
+
for line in response.iter_lines():
|
| 86 |
+
if line:
|
| 87 |
+
try:
|
| 88 |
+
data = json.loads(line)
|
| 89 |
+
if "message" in data and "content" in data["message"]:
|
| 90 |
+
chunk = data["message"]["content"]
|
| 91 |
+
full_response += chunk
|
| 92 |
+
yield full_response
|
| 93 |
+
except:
|
| 94 |
+
continue
|
| 95 |
+
|
| 96 |
+
except Exception as e:
|
| 97 |
+
yield f"❌ Error: {str(e)}"
|
| 98 |
+
|
| 99 |
+
def generate_code(prompt: str, language: str, model_name: str):
|
| 100 |
+
"""Generate code from description"""
|
| 101 |
+
|
| 102 |
+
if not prompt.strip():
|
| 103 |
+
return "Please describe what you want to build."
|
| 104 |
+
|
| 105 |
+
if not check_ollama():
|
| 106 |
+
return "⏳ Ollama is starting... please wait and try again."
|
| 107 |
+
|
| 108 |
+
model = MODELS.get(model_name, "qwen2.5-coder:7b")
|
| 109 |
+
|
| 110 |
+
full_prompt = f"""Write {language} code for:
|
| 111 |
+
|
| 112 |
+
{prompt}
|
| 113 |
+
|
| 114 |
+
Requirements:
|
| 115 |
+
- Clean, well-commented code
|
| 116 |
+
- Follow {language} best practices
|
| 117 |
+
- Include error handling
|
| 118 |
+
|
| 119 |
+
Output ONLY the code in a markdown code block, no explanations."""
|
| 120 |
+
|
| 121 |
+
try:
|
| 122 |
+
response = requests.post(
|
| 123 |
+
f"{OLLAMA_URL}/api/generate",
|
| 124 |
+
json={
|
| 125 |
+
"model": model,
|
| 126 |
+
"prompt": full_prompt,
|
| 127 |
+
"stream": False,
|
| 128 |
+
"options": {"temperature": 0.3, "num_predict": 2048}
|
| 129 |
+
},
|
| 130 |
+
timeout=300
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
if response.status_code == 200:
|
| 134 |
+
result = response.json().get("response", "")
|
| 135 |
+
# Clean up markdown
|
| 136 |
+
if "```" in result:
|
| 137 |
+
parts = result.split("```")
|
| 138 |
+
if len(parts) >= 2:
|
| 139 |
+
code = parts[1]
|
| 140 |
+
if "\n" in code:
|
| 141 |
+
code = code.split("\n", 1)[-1]
|
| 142 |
+
return code.strip()
|
| 143 |
+
return result
|
| 144 |
+
return f"Error: {response.text}"
|
| 145 |
+
|
| 146 |
+
except Exception as e:
|
| 147 |
+
return f"❌ Error: {str(e)}"
|
| 148 |
+
|
| 149 |
+
def explain_code(code: str, model_name: str):
|
| 150 |
+
"""Explain code"""
|
| 151 |
+
|
| 152 |
+
if not code.strip():
|
| 153 |
+
return "Please paste code to explain."
|
| 154 |
+
|
| 155 |
+
if not check_ollama():
|
| 156 |
+
return "⏳ Ollama starting... please wait."
|
| 157 |
+
|
| 158 |
+
model = MODELS.get(model_name, "qwen2.5-coder:7b")
|
| 159 |
+
|
| 160 |
+
prompt = f"""Explain this code in detail:
|
| 161 |
+
|
| 162 |
+
```
|
| 163 |
+
{code}
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
Cover:
|
| 167 |
+
1. **Purpose**: What does it do?
|
| 168 |
+
2. **How it works**: Step by step
|
| 169 |
+
3. **Key concepts**: Important programming concepts
|
| 170 |
+
4. **Improvements**: Suggestions for better code"""
|
| 171 |
+
|
| 172 |
+
try:
|
| 173 |
+
response = requests.post(
|
| 174 |
+
f"{OLLAMA_URL}/api/generate",
|
| 175 |
+
json={
|
| 176 |
+
"model": model,
|
| 177 |
+
"prompt": prompt,
|
| 178 |
+
"stream": False,
|
| 179 |
+
"options": {"temperature": 0.5, "num_predict": 2048}
|
| 180 |
+
},
|
| 181 |
+
timeout=300
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
if response.status_code == 200:
|
| 185 |
+
return response.json().get("response", "")
|
| 186 |
+
return f"Error: {response.text}"
|
| 187 |
+
|
| 188 |
+
except Exception as e:
|
| 189 |
+
return f"❌ Error: {str(e)}"
|
| 190 |
+
|
| 191 |
+
def fix_code(code: str, error_msg: str, model_name: str):
|
| 192 |
+
"""Fix buggy code"""
|
| 193 |
+
|
| 194 |
+
if not code.strip():
|
| 195 |
+
return "Please paste code to fix."
|
| 196 |
+
|
| 197 |
+
if not check_ollama():
|
| 198 |
+
return "⏳ Ollama starting... please wait."
|
| 199 |
+
|
| 200 |
+
model = MODELS.get(model_name, "qwen2.5-coder:7b")
|
| 201 |
+
|
| 202 |
+
prompt = f"""Fix this buggy code:
|
| 203 |
+
|
| 204 |
+
**Code:**
|
| 205 |
+
```
|
| 206 |
+
{code}
|
| 207 |
+
```
|
| 208 |
+
|
| 209 |
+
**Error:**
|
| 210 |
+
{error_msg if error_msg.strip() else "Code doesn't work correctly"}
|
| 211 |
+
|
| 212 |
+
Please:
|
| 213 |
+
1. Identify the bug
|
| 214 |
+
2. Explain what's wrong
|
| 215 |
+
3. Provide fixed code
|
| 216 |
+
4. Explain the fix"""
|
| 217 |
+
|
| 218 |
+
try:
|
| 219 |
+
response = requests.post(
|
| 220 |
+
f"{OLLAMA_URL}/api/generate",
|
| 221 |
+
json={
|
| 222 |
+
"model": model,
|
| 223 |
+
"prompt": prompt,
|
| 224 |
+
"stream": False,
|
| 225 |
+
"options": {"temperature": 0.3, "num_predict": 2048}
|
| 226 |
+
},
|
| 227 |
+
timeout=300
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
if response.status_code == 200:
|
| 231 |
+
return response.json().get("response", "")
|
| 232 |
+
return f"Error: {response.text}"
|
| 233 |
+
|
| 234 |
+
except Exception as e:
|
| 235 |
+
return f"❌ Error: {str(e)}"
|
| 236 |
+
|
| 237 |
+
def review_code(code: str, model_name: str):
|
| 238 |
+
"""Review code"""
|
| 239 |
+
|
| 240 |
+
if not code.strip():
|
| 241 |
+
return "Please paste code to review."
|
| 242 |
+
|
| 243 |
+
if not check_ollama():
|
| 244 |
+
return "⏳ Ollama starting... please wait."
|
| 245 |
+
|
| 246 |
+
model = MODELS.get(model_name, "qwen2.5-coder:7b")
|
| 247 |
+
|
| 248 |
+
prompt = f"""Review this code:
|
| 249 |
+
|
| 250 |
+
```
|
| 251 |
+
{code}
|
| 252 |
+
```
|
| 253 |
+
|
| 254 |
+
Evaluate:
|
| 255 |
+
1. **Code Quality**: Clean, readable?
|
| 256 |
+
2. **Best Practices**: Follows conventions?
|
| 257 |
+
3. **Bugs**: Any issues?
|
| 258 |
+
4. **Performance**: Any concerns?
|
| 259 |
+
5. **Security**: Any vulnerabilities?
|
| 260 |
+
6. **Improvements**: Specific suggestions with examples"""
|
| 261 |
+
|
| 262 |
+
try:
|
| 263 |
+
response = requests.post(
|
| 264 |
+
f"{OLLAMA_URL}/api/generate",
|
| 265 |
+
json={
|
| 266 |
+
"model": model,
|
| 267 |
+
"prompt": prompt,
|
| 268 |
+
"stream": False,
|
| 269 |
+
"options": {"temperature": 0.5, "num_predict": 2048}
|
| 270 |
+
},
|
| 271 |
+
timeout=300
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
if response.status_code == 200:
|
| 275 |
+
return response.json().get("response", "")
|
| 276 |
+
return f"Error: {response.text}"
|
| 277 |
+
|
| 278 |
+
except Exception as e:
|
| 279 |
+
return f"❌ Error: {str(e)}"
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
# ============== BUILD UI ==============
|
| 283 |
+
|
| 284 |
+
with gr.Blocks(
|
| 285 |
+
title="🔥 GOD Coding Machine",
|
| 286 |
+
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"),
|
| 287 |
+
) as demo:
|
| 288 |
+
|
| 289 |
+
gr.Markdown("""
|
| 290 |
+
# 🔥 FREE GOD Coding Machine
|
| 291 |
+
### AI Coding Assistant - Running Locally on HuggingFace Spaces
|
| 292 |
+
|
| 293 |
+
**🚀 Docker Edition** • Ollama running locally • **No rate limits!** • 18GB RAM
|
| 294 |
+
""")
|
| 295 |
+
|
| 296 |
+
with gr.Row():
|
| 297 |
+
model_dropdown = gr.Dropdown(
|
| 298 |
+
choices=list(MODELS.keys()),
|
| 299 |
+
value="Qwen2.5-Coder 7B (Best)",
|
| 300 |
+
label="🤖 Model",
|
| 301 |
+
scale=2
|
| 302 |
+
)
|
| 303 |
+
temperature = gr.Slider(
|
| 304 |
+
0.0, 1.0, value=0.7, step=0.1,
|
| 305 |
+
label="🌡️ Temperature", scale=1
|
| 306 |
+
)
|
| 307 |
+
max_tokens = gr.Slider(
|
| 308 |
+
256, 4096, value=2048, step=256,
|
| 309 |
+
label="📏 Max Tokens", scale=1
|
| 310 |
+
)
|
| 311 |
+
|
| 312 |
+
with gr.Tabs():
|
| 313 |
+
|
| 314 |
+
# Chat Tab
|
| 315 |
+
with gr.TabItem("💬 Chat"):
|
| 316 |
+
chatbot = gr.Chatbot(height=450, show_label=False)
|
| 317 |
+
|
| 318 |
+
with gr.Row():
|
| 319 |
+
msg = gr.Textbox(
|
| 320 |
+
placeholder="Ask anything about coding...",
|
| 321 |
+
show_label=False, scale=9, container=False
|
| 322 |
+
)
|
| 323 |
+
send_btn = gr.Button("Send", variant="primary", scale=1)
|
| 324 |
+
|
| 325 |
+
clear_btn = gr.Button("🗑️ Clear")
|
| 326 |
+
|
| 327 |
+
gr.Examples([
|
| 328 |
+
"Write a Python function to find all prime numbers up to n",
|
| 329 |
+
"Explain async/await in JavaScript",
|
| 330 |
+
"How do I implement a REST API in FastAPI?",
|
| 331 |
+
"What's the difference between a list and tuple in Python?",
|
| 332 |
+
], inputs=msg)
|
| 333 |
+
|
| 334 |
+
# Generate Tab
|
| 335 |
+
with gr.TabItem("⚡ Generate Code"):
|
| 336 |
+
with gr.Row():
|
| 337 |
+
with gr.Column():
|
| 338 |
+
gen_prompt = gr.Textbox(
|
| 339 |
+
label="📝 Describe what you want",
|
| 340 |
+
placeholder="A function that...", lines=4
|
| 341 |
+
)
|
| 342 |
+
gen_lang = gr.Dropdown(
|
| 343 |
+
["Python", "JavaScript", "TypeScript", "Rust", "Go", "Java", "C++", "C#", "Ruby", "PHP"],
|
| 344 |
+
value="Python", label="💻 Language"
|
| 345 |
+
)
|
| 346 |
+
gen_btn = gr.Button("🚀 Generate", variant="primary", size="lg")
|
| 347 |
+
|
| 348 |
+
with gr.Column():
|
| 349 |
+
gen_output = gr.Code(label="Generated Code", language="python", lines=20)
|
| 350 |
+
|
| 351 |
+
gr.Examples([
|
| 352 |
+
["A function to merge two sorted linked lists", "Python"],
|
| 353 |
+
["A debounce hook for React", "TypeScript"],
|
| 354 |
+
["Binary search tree with insert and search", "Java"],
|
| 355 |
+
], inputs=[gen_prompt, gen_lang])
|
| 356 |
+
|
| 357 |
+
# Explain Tab
|
| 358 |
+
with gr.TabItem("🔍 Explain Code"):
|
| 359 |
+
with gr.Row():
|
| 360 |
+
with gr.Column():
|
| 361 |
+
explain_input = gr.Code(label="📋 Paste code", language="python", lines=15)
|
| 362 |
+
explain_btn = gr.Button("🔍 Explain", variant="primary", size="lg")
|
| 363 |
+
with gr.Column():
|
| 364 |
+
explain_output = gr.Markdown(label="Explanation")
|
| 365 |
+
|
| 366 |
+
# Fix Tab
|
| 367 |
+
with gr.TabItem("🔧 Fix Code"):
|
| 368 |
+
with gr.Row():
|
| 369 |
+
with gr.Column():
|
| 370 |
+
fix_input = gr.Code(label="🐛 Buggy code", language="python", lines=12)
|
| 371 |
+
fix_error = gr.Textbox(label="❌ Error (optional)", lines=3)
|
| 372 |
+
fix_btn = gr.Button("🔧 Fix", variant="primary", size="lg")
|
| 373 |
+
with gr.Column():
|
| 374 |
+
fix_output = gr.Markdown(label="Solution")
|
| 375 |
+
|
| 376 |
+
# Review Tab
|
| 377 |
+
with gr.TabItem("📝 Code Review"):
|
| 378 |
+
with gr.Row():
|
| 379 |
+
with gr.Column():
|
| 380 |
+
review_input = gr.Code(label="📋 Code to review", language="python", lines=15)
|
| 381 |
+
review_btn = gr.Button("📝 Review", variant="primary", size="lg")
|
| 382 |
+
with gr.Column():
|
| 383 |
+
review_output = gr.Markdown(label="Review")
|
| 384 |
+
|
| 385 |
+
gr.Markdown("""
|
| 386 |
+
---
|
| 387 |
+
<center>
|
| 388 |
+
🔥 <b>Docker Edition</b> - Ollama running locally | <b>Models</b>: Qwen2.5-Coder 7B & 3B | <b>No rate limits!</b>
|
| 389 |
+
</center>
|
| 390 |
+
""")
|
| 391 |
+
|
| 392 |
+
# Event handlers
|
| 393 |
+
def respond(message, history, model, temp, max_tok):
|
| 394 |
+
history = history or []
|
| 395 |
+
response = ""
|
| 396 |
+
for chunk in chat_stream(message, history, model, temp, max_tok):
|
| 397 |
+
response = chunk
|
| 398 |
+
yield history + [[message, response]], ""
|
| 399 |
+
|
| 400 |
+
msg.submit(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 401 |
+
send_btn.click(respond, [msg, chatbot, model_dropdown, temperature, max_tokens], [chatbot, msg])
|
| 402 |
+
clear_btn.click(lambda: [], None, chatbot)
|
| 403 |
+
|
| 404 |
+
gen_btn.click(generate_code, [gen_prompt, gen_lang, model_dropdown], gen_output)
|
| 405 |
+
explain_btn.click(explain_code, [explain_input, model_dropdown], explain_output)
|
| 406 |
+
fix_btn.click(fix_code, [fix_input, fix_error, model_dropdown], fix_output)
|
| 407 |
+
review_btn.click(review_code, [review_input, model_dropdown], review_output)
|
| 408 |
+
|
| 409 |
+
if __name__ == "__main__":
|
| 410 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
docker-space/entrypoint.sh
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
echo "============================================"
|
| 4 |
+
echo "🔥 GOD CODING MACHINE - Docker Edition"
|
| 5 |
+
echo " 18GB RAM | CPU | No Rate Limits!"
|
| 6 |
+
echo "============================================"
|
| 7 |
+
echo ""
|
| 8 |
+
|
| 9 |
+
# Start Ollama in background
|
| 10 |
+
echo "🚀 Starting Ollama server..."
|
| 11 |
+
ollama serve &
|
| 12 |
+
|
| 13 |
+
# Wait for Ollama to be ready
|
| 14 |
+
echo "⏳ Waiting for Ollama..."
|
| 15 |
+
for i in {1..60}; do
|
| 16 |
+
if curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
|
| 17 |
+
echo "✅ Ollama is ready!"
|
| 18 |
+
break
|
| 19 |
+
fi
|
| 20 |
+
sleep 1
|
| 21 |
+
done
|
| 22 |
+
|
| 23 |
+
# Pull models optimized for 18GB RAM + CPU
|
| 24 |
+
echo ""
|
| 25 |
+
echo "📦 Downloading models (first run takes ~5-10 min)..."
|
| 26 |
+
echo ""
|
| 27 |
+
|
| 28 |
+
# Main model - Qwen 2.5 Coder 7B (best quality for our RAM)
|
| 29 |
+
echo "📥 Pulling Qwen2.5-Coder:7b (main model)..."
|
| 30 |
+
ollama pull qwen2.5-coder:7b
|
| 31 |
+
|
| 32 |
+
# Smaller fast model for quick tasks
|
| 33 |
+
echo "📥 Pulling Qwen2.5-Coder:3b (fast model)..."
|
| 34 |
+
ollama pull qwen2.5-coder:3b
|
| 35 |
+
|
| 36 |
+
echo ""
|
| 37 |
+
echo "============================================"
|
| 38 |
+
echo "✅ All models ready!"
|
| 39 |
+
echo "============================================"
|
| 40 |
+
ollama list
|
| 41 |
+
echo ""
|
| 42 |
+
echo "🌐 Starting Gradio interface..."
|
| 43 |
+
echo ""
|
| 44 |
+
|
| 45 |
+
# Start the Gradio app
|
| 46 |
+
python app.py
|