Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,24 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
model_name = "
|
|
|
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
def generate_html(prompt):
|
| 11 |
-
|
| 12 |
-
inputs = tokenizer.encode(
|
| 13 |
outputs = model.generate(inputs, max_length=1500, temperature=0.7, do_sample=True)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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="
|
| 28 |
).launch()
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# ✅ Use open-access model
|
| 6 |
+
model_name = "deepseek-ai/deepseek-coder-6.7b-instruct"
|
| 7 |
+
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
|
| 10 |
|
| 11 |
def generate_html(prompt):
|
| 12 |
+
input_prompt = f"Generate only HTML, CSS, and JS website code from this idea:\n\n{prompt}\n\nOnly return code output:"
|
| 13 |
+
inputs = tokenizer.encode(input_prompt, return_tensors="pt", truncation=True, max_length=1024)
|
| 14 |
outputs = model.generate(inputs, max_length=1500, temperature=0.7, do_sample=True)
|
| 15 |
+
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
first_tag = decoded.find('<')
|
| 17 |
+
return decoded[first_tag:] if first_tag != -1 else decoded
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
gr.Interface(
|
| 20 |
fn=generate_html,
|
| 21 |
inputs=gr.Textbox(lines=6, label="Describe your website idea (English or Hindi)"),
|
| 22 |
+
outputs=gr.Code(label="Generated HTML/CSS/JS Code"),
|
| 23 |
title="SKORD AI Website Generator",
|
| 24 |
+
description="Type your website idea and receive full HTML/CSS/JS code (pure code output only)."
|
| 25 |
).launch()
|