Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load Starcoder model (code generation)
|
| 6 |
+
model_name = "bigcode/starcoder"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
def generate_html(prompt):
|
| 11 |
+
input_text = f"Generate only HTML/CSS/JS code for this website idea:\n{prompt}"
|
| 12 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt", truncation=True, max_length=1024)
|
| 13 |
+
outputs = model.generate(inputs, max_length=1500, temperature=0.7, do_sample=True)
|
| 14 |
+
code = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
|
| 16 |
+
# Keep only the HTML part from the output
|
| 17 |
+
first_html_index = code.find('<')
|
| 18 |
+
if first_html_index != -1:
|
| 19 |
+
return code[first_html_index:]
|
| 20 |
+
return code
|
| 21 |
+
|
| 22 |
+
gr.Interface(
|
| 23 |
+
fn=generate_html,
|
| 24 |
+
inputs=gr.Textbox(lines=6, label="Describe your website idea (English or Hindi)"),
|
| 25 |
+
outputs=gr.Code(label="Generated HTML/CSS/JS"),
|
| 26 |
+
title="SKORD AI Website Generator",
|
| 27 |
+
description="Get only HTML/CSS/JS code from your idea using AI. Works in English and Hindi."
|
| 28 |
+
).launch()
|