yashmit12345 commited on
Commit
0358312
·
verified ·
1 Parent(s): 01b1ef9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
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()