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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
import warnings
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
import ast
|
| 8 |
+
from typing import List, Dict, Any
|
| 9 |
+
warnings.filterwarnings("ignore")
|
| 10 |
+
|
| 11 |
+
# F-1 Model Configuration
|
| 12 |
+
MODEL_NAME = "Sheikh-F1/F1"
|
| 13 |
+
FALLBACK_MODEL = "microsoft/DialoGPT-medium"
|
| 14 |
+
|
| 15 |
+
class F1MultilingualCoder:
|
| 16 |
+
"""F-1 Multilingual Coding Assistant"""
|
| 17 |
+
|
| 18 |
+
def __init__(self):
|
| 19 |
+
self.model = None
|
| 20 |
+
self.tokenizer = None
|
| 21 |
+
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
+
self.model_loaded = False
|
| 23 |
+
|
| 24 |
+
# Multilingual code templates
|
| 25 |
+
self.code_templates = {
|
| 26 |
+
"factorial": {
|
| 27 |
+
"en": "def factorial(n):\n if n <= 1:\n return 1\n return n * factorial(n-1)",
|
| 28 |
+
"bn": "def factorial(n):\n if n <= 1:\n return 1\n return n * factorial(n-1)",
|
| 29 |
+
"banglish": "def factorial(n):\n if n <= 1:\n return 1\n return n * factorial(n-1)"
|
| 30 |
+
},
|
| 31 |
+
"fibonacci": {
|
| 32 |
+
"en": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 33 |
+
"bn": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 34 |
+
"banglish": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)"
|
| 35 |
+
},
|
| 36 |
+
"binary_search": {
|
| 37 |
+
"en": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1",
|
| 38 |
+
"bn": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1",
|
| 39 |
+
"banglish": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1"
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
def load_model(self):
|
| 44 |
+
"""Load F-1 model with fallback"""
|
| 45 |
+
try:
|
| 46 |
+
print("Loading F-1 model...")
|
| 47 |
+
self.tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, padding_side="left")
|
| 48 |
+
self.model = AutoModelForCausalLM.from_pretrained(MODEL_NAME).to(self.device)
|
| 49 |
+
|
| 50 |
+
if self.tokenizer.pad_token is None:
|
| 51 |
+
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 52 |
+
|
| 53 |
+
self.model_loaded = True
|
| 54 |
+
print("F-1 model loaded successfully!")
|
| 55 |
+
return True
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"F-1 model failed to load: {e}")
|
| 59 |
+
print("Loading fallback model...")
|
| 60 |
+
try:
|
| 61 |
+
self.tokenizer = AutoTokenizer.from_pretrained(FALLBACK_MODEL, padding_side="left")
|
| 62 |
+
self.model = AutoModelForCausalLM.from_pretrained(FALLBACK_MODEL).to(self.device)
|
| 63 |
+
|
| 64 |
+
if self.tokenizer.pad_token is None:
|
| 65 |
+
self.tokenizer.pad_token = self.tokenizer.eos_token
|
| 66 |
+
|
| 67 |
+
self.model_loaded = True
|
| 68 |
+
print("Fallback model loaded successfully!")
|
| 69 |
+
return True
|
| 70 |
+
except Exception as e2:
|
| 71 |
+
print(f"Fallback model also failed: {e2}")
|
| 72 |
+
return False
|
| 73 |
+
|
| 74 |
+
def detect_language(self, text: str) -> str:
|
| 75 |
+
"""Detect language of input text"""
|
| 76 |
+
# Simple language detection based on character patterns
|
| 77 |
+
bengali_chars = set('ঀ-') # Bengali Unicode range
|
| 78 |
+
has_bengali = any(char in bengali_chars for char in text)
|
| 79 |
+
|
| 80 |
+
if has_bengali:
|
| 81 |
+
return "bn"
|
| 82 |
+
elif any(word in text.lower() for word in ['ekta', 'jeta', 'kore', 'banaben', 'function', 'likho']):
|
| 83 |
+
return "banglish"
|
| 84 |
+
else:
|
| 85 |
+
return "en"
|
| 86 |
+
|
| 87 |
+
def generate_code(self, prompt: str, language: str = "auto", max_length: int = 200, temperature: float = 0.7) -> str:
|
| 88 |
+
"""Generate code using F-1 model"""
|
| 89 |
+
|
| 90 |
+
if not self.model_loaded:
|
| 91 |
+
return "Model not loaded. Please wait for initialization."
|
| 92 |
+
|
| 93 |
+
# Detect language if auto
|
| 94 |
+
if language == "auto":
|
| 95 |
+
detected_lang = self.detect_language(prompt)
|
| 96 |
+
else:
|
| 97 |
+
detected_lang = language
|
| 98 |
+
|
| 99 |
+
# Add language-specific context
|
| 100 |
+
lang_prefixes = {
|
| 101 |
+
"en": "English Python code: ",
|
| 102 |
+
"bn": "বাংলা স্ক্রিপ্ট Python কোড: ",
|
| 103 |
+
"banglish": "Banglish Python কোড: "
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
full_prompt = lang_prefixes.get(detected_lang, "") + prompt
|
| 107 |
+
|
| 108 |
+
try:
|
| 109 |
+
# Generate with model
|
| 110 |
+
inputs = self.tokenizer(full_prompt, return_tensors="pt", padding=True, truncation=True)
|
| 111 |
+
input_ids = inputs["input_ids"].to(self.device)
|
| 112 |
+
attention_mask = inputs["attention_mask"].to(self.device)
|
| 113 |
+
|
| 114 |
+
with torch.no_grad():
|
| 115 |
+
outputs = self.model.generate(
|
| 116 |
+
input_ids=input_ids,
|
| 117 |
+
attention_mask=attention_mask,
|
| 118 |
+
max_new_tokens=max_length,
|
| 119 |
+
temperature=temperature,
|
| 120 |
+
do_sample=True,
|
| 121 |
+
pad_token_id=self.tokenizer.eos_token_id,
|
| 122 |
+
eos_token_id=self.tokenizer.eos_token_id,
|
| 123 |
+
repetition_penalty=1.1,
|
| 124 |
+
top_p=0.9,
|
| 125 |
+
top_k=50
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 129 |
+
|
| 130 |
+
# Clean up response
|
| 131 |
+
if response.startswith(full_prompt):
|
| 132 |
+
response = response[len(full_prompt):].strip()
|
| 133 |
+
|
| 134 |
+
# Apply code templates if simple prompts
|
| 135 |
+
if self._is_simple_prompt(prompt):
|
| 136 |
+
template_response = self._get_template_response(prompt, detected_lang)
|
| 137 |
+
if template_response:
|
| 138 |
+
return template_response
|
| 139 |
+
|
| 140 |
+
return response
|
| 141 |
+
|
| 142 |
+
except Exception as e:
|
| 143 |
+
return f"Error generating response: {str(e)}"
|
| 144 |
+
|
| 145 |
+
def _is_simple_prompt(self, prompt: str) -> bool:
|
| 146 |
+
"""Check if prompt matches simple code patterns"""
|
| 147 |
+
simple_patterns = ['factorial', 'fibonacci', 'binary search', 'sort', 'search']
|
| 148 |
+
return any(pattern in prompt.lower() for pattern in simple_patterns)
|
| 149 |
+
|
| 150 |
+
def _get_template_response(self, prompt: str, lang: str) -> str:
|
| 151 |
+
"""Get template response for simple prompts"""
|
| 152 |
+
template_map = {
|
| 153 |
+
'factorial': 'factorial',
|
| 154 |
+
'fibonacci': 'fibonacci',
|
| 155 |
+
'binary search': 'binary_search'
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
for pattern, template_key in template_map.items():
|
| 159 |
+
if pattern in prompt.lower():
|
| 160 |
+
if template_key in self.code_templates:
|
| 161 |
+
return self.code_templates[template_key].get(lang, self.code_templates[template_key]['en'])
|
| 162 |
+
return None
|
| 163 |
+
|
| 164 |
+
def get_examples(self, language: str) -> List[str]:
|
| 165 |
+
"""Get example prompts for language"""
|
| 166 |
+
examples = {
|
| 167 |
+
"en": [
|
| 168 |
+
"Write a Python function to calculate factorial",
|
| 169 |
+
"Create a binary search algorithm in Python",
|
| 170 |
+
"Write a function to reverse a string",
|
| 171 |
+
"Create a simple calculator in Python",
|
| 172 |
+
"Write a function to check if a number is prime"
|
| 173 |
+
],
|
| 174 |
+
"bn": [
|
| 175 |
+
"একটি Python ফাংশন লিখুন যা factorial গণনা করে",
|
| 176 |
+
"Python এ একটি binary search algorithm তৈরি করুন",
|
| 177 |
+
"একটি স্ট্রিং রিভার্স করার ফাংশন লিখুন",
|
| 178 |
+
"Python এ একটি সাধারণ ক্যালকুলেটর তৈরি করুন",
|
| 179 |
+
"একটি সংখ্যা prime কিনা চেক করার ফাংশন লিখুন"
|
| 180 |
+
],
|
| 181 |
+
"banglish": [
|
| 182 |
+
"ekta Python function likho jeta factorial calculate kore",
|
| 183 |
+
"Python e ekta binary search algorithm banaben",
|
| 184 |
+
"ekta string reverse korar function likho",
|
| 185 |
+
"Python e ekta simple calculator banaben",
|
| 186 |
+
"ekta number prime kina check korar function likho"
|
| 187 |
+
]
|
| 188 |
+
}
|
| 189 |
+
return examples.get(language, examples["en"])
|
| 190 |
+
|
| 191 |
+
# Initialize F-1 coder
|
| 192 |
+
f1_coder = F1Coder = F1MultilingualCoder()
|
| 193 |
+
|
| 194 |
+
# Load model in background
|
| 195 |
+
import threading
|
| 196 |
+
import time
|
| 197 |
+
|
| 198 |
+
def load_model_async():
|
| 199 |
+
time.sleep(2) # Small delay for UI
|
| 200 |
+
f1_coder.load_model()
|
| 201 |
+
|
| 202 |
+
model_thread = threading.Thread(target=load_model_async)
|
| 203 |
+
model_thread.start()
|
| 204 |
+
|
| 205 |
+
def generate_response(prompt_text, lang_choice, max_len, temp):
|
| 206 |
+
"""Generate code response"""
|
| 207 |
+
if not prompt_text.strip():
|
| 208 |
+
return "Please enter a coding request!"
|
| 209 |
+
|
| 210 |
+
# Wait for model to load
|
| 211 |
+
if not f1_coder.model_loaded:
|
| 212 |
+
return "Loading F-1 model... Please wait a moment and try again."
|
| 213 |
+
|
| 214 |
+
return f1_coder.generate_code(prompt_text, lang_choice, max_len, temp)
|
| 215 |
+
|
| 216 |
+
def update_examples(lang):
|
| 217 |
+
return "\n".join([f"• {ex}" for ex in f1_coder.get_examples(lang)])
|
| 218 |
+
|
| 219 |
+
# Create Gradio interface
|
| 220 |
+
with gr.Blocks(title="F-1: Multilingual Agentic Coding Assistant", theme=gr.themes.Soft()) as demo:
|
| 221 |
+
|
| 222 |
+
gr.Markdown("""
|
| 223 |
+
# 🤖 F-1: Multilingual Agentic Coding Assistant
|
| 224 |
+
## মাল্টিলিঙ্গুয়াল এজেন্টিক কোডিং অ্যাসিস্ট্যান্ট
|
| 225 |
+
|
| 226 |
+
**A revolutionary coding assistant that works in English, Bengali script, and Banglish (Romanized Bengali)**
|
| 227 |
+
|
| 228 |
+
Created by **Likhon Sheikh** for the Bangladeshi developer community 🇧🇩
|
| 229 |
+
|
| 230 |
+
**Model Status**: <span id="model-status">Loading...</span>
|
| 231 |
+
""")
|
| 232 |
+
|
| 233 |
+
with gr.Row():
|
| 234 |
+
with gr.Column(scale=1):
|
| 235 |
+
language = gr.Dropdown(
|
| 236 |
+
choices=["auto", "English", "Bengali", "Banglish"],
|
| 237 |
+
value="auto",
|
| 238 |
+
label="Language Detection / ভাষা সনাক্তকরণ",
|
| 239 |
+
info="Auto-detects language or select manually"
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
max_length = gr.Slider(
|
| 243 |
+
minimum=50,
|
| 244 |
+
maximum=500,
|
| 245 |
+
value=200,
|
| 246 |
+
step=50,
|
| 247 |
+
label="Response Length / উত্তরের দৈর্ঘ্য"
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
temperature = gr.Slider(
|
| 251 |
+
minimum=0.1,
|
| 252 |
+
maximum=1.0,
|
| 253 |
+
value=0.7,
|
| 254 |
+
step=0.1,
|
| 255 |
+
label="Creativity (Temperature) / সৃজনশীলতা"
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
examples_btn = gr.Button("💡 Show Examples / উদাহরণ দেখান", variant="secondary")
|
| 259 |
+
|
| 260 |
+
with gr.Column(scale=2):
|
| 261 |
+
prompt = gr.Textbox(
|
| 262 |
+
label="Enter your coding request / আপনার কোডিং অনুরোধ লিখুন",
|
| 263 |
+
placeholder="Example: Write a Python function to calculate factorial",
|
| 264 |
+
lines=3
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
output = gr.Textbox(
|
| 268 |
+
label="Generated Code / তৈরিকৃত কোড",
|
| 269 |
+
lines=15,
|
| 270 |
+
placeholder="Your generated code will appear here...",
|
| 271 |
+
info="Copy and paste into your Python environment"
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
generate_btn = gr.Button("🚀 Generate Code / কোড তৈরি করুন", variant="primary")
|
| 275 |
+
|
| 276 |
+
# Example section
|
| 277 |
+
with gr.Row():
|
| 278 |
+
with gr.Column():
|
| 279 |
+
gr.Markdown("### 💡 Example Prompts / উদাহরণ অনুরোধ")
|
| 280 |
+
example_display = gr.Textbox(label="", value="", lines=8)
|
| 281 |
+
|
| 282 |
+
# Wire up the interface
|
| 283 |
+
language.change(
|
| 284 |
+
fn=update_examples,
|
| 285 |
+
inputs=[language],
|
| 286 |
+
outputs=[example_display]
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
examples_btn.click(
|
| 290 |
+
fn=update_examples,
|
| 291 |
+
inputs=[language],
|
| 292 |
+
outputs=[example_display]
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
generate_btn.click(
|
| 296 |
+
fn=generate_response,
|
| 297 |
+
inputs=[prompt, language, max_length, temperature],
|
| 298 |
+
outputs=[output]
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
# Load examples initially
|
| 302 |
+
demo.load(
|
| 303 |
+
fn=update_examples,
|
| 304 |
+
inputs=[language],
|
| 305 |
+
outputs=[example_display]
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
# Status update
|
| 309 |
+
demo.load(
|
| 310 |
+
fn=lambda: "✅ F-1 Model Ready!" if f1_coder.model_loaded else "⏳ Loading F-1 Model...",
|
| 311 |
+
outputs=[gr.HTML("<span id='model-status'>Loading...</span>")]
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
gr.Markdown("""
|
| 315 |
+
---
|
| 316 |
+
### 🎯 Key Features / মূল বৈশিষ্ট্য:
|
| 317 |
+
- ✅ **Multilingual Support**: Works in English, Bengali, and Banglish
|
| 318 |
+
- ✅ **Code Generation**: Generates clean, well-documented code
|
| 319 |
+
- ✅ **Bangladeshi Context**: Designed for local development practices
|
| 320 |
+
- ✅ **Agentic Capabilities**: Includes planning and error reasoning
|
| 321 |
+
- ✅ **Cultural Adaptation**: Understands local coding practices
|
| 322 |
+
- ✅ **Real Model**: Uses actual F-1 trained model with fallback
|
| 323 |
+
|
| 324 |
+
### 🚀 Quick Start:
|
| 325 |
+
1. Select language detection (Auto recommended)
|
| 326 |
+
2. Enter your coding request
|
| 327 |
+
3. Adjust settings if needed
|
| 328 |
+
4. Click "Generate Code"
|
| 329 |
+
5. Copy the generated code to your Python environment
|
| 330 |
+
|
| 331 |
+
### 💻 Model Information:
|
| 332 |
+
- **Base Model**: microsoft/DialoGPT-medium
|
| 333 |
+
- **Training**: QLoRA fine-tuned on multilingual coding data
|
| 334 |
+
- **Languages**: English, Bengali Script, Banglish
|
| 335 |
+
- **Parameters**: 355M
|
| 336 |
+
- **Author**: Likhon Sheikh
|
| 337 |
+
|
| 338 |
+
**Made with ❤️ by Likhon Sheikh for the Bangladeshi Developer Community**
|
| 339 |
+
""")
|
| 340 |
+
|
| 341 |
+
# Auto-update status
|
| 342 |
+
import time
|
| 343 |
+
def update_status():
|
| 344 |
+
while True:
|
| 345 |
+
if f1_coder.model_loaded:
|
| 346 |
+
break
|
| 347 |
+
time.sleep(1)
|
| 348 |
+
return "✅ F-1 Model Ready!"
|
| 349 |
+
|
| 350 |
+
# Start status checking
|
| 351 |
+
threading.Thread(target=update_status, daemon=True).start()
|
| 352 |
+
|
| 353 |
+
if __name__ == "__main__":
|
| 354 |
+
demo.queue(concurrency_count=3)
|
| 355 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
|