devXpert commited on
Commit
3df63a5
·
verified ·
1 Parent(s): 421a1ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
app.py CHANGED
@@ -1,33 +1,22 @@
1
- from transformers import pipeline
2
  import gradio as gr
 
3
 
4
- # Load code generation model (switch to GPU if possible in settings)
5
- generator = pipeline("text-generation", model="deepseek-ai/deepseek-coder-6.7b-instruct")
6
-
7
- # Function to generate website code from user prompt
8
- def generate_website_code(prompt):
9
- full_prompt = f"""You are a senior web developer. Based on the following instructions, generate a full HTML5 website including CSS and JavaScript inside <style> and <script> tags.
10
-
11
- Instructions:
12
- {prompt}
13
 
14
- Return only the complete code inside <html>...</html> tags, ready to save as an .html file.
15
- """
16
- output = generator(full_prompt, max_new_tokens=2048, temperature=0.7)[0]["generated_text"]
 
17
 
18
- # Extract only the part starting with <html> to avoid model's intro text
19
- html_start = output.find("<html")
20
- if html_start != -1:
21
- return output[html_start:]
22
- return output
23
-
24
- # Gradio UI
25
- iface = gr.Interface(
26
- fn=generate_website_code,
27
- inputs=gr.Textbox(lines=8, label="Describe your website (Prompt)"),
28
- outputs=gr.Code(label="Generated HTML Website Code"),
29
- title="AI Website Generator",
30
- description="Enter a prompt describing your website. Example: 'Create a modern cafe website using beige and brown colors. The brand is BrewNest. Include food items, transitions, and animations.'",
31
- )
32
 
33
- iface.launch()
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the text-to-text generation model
5
+ generator = pipeline("text2text-generation", model="google/flan-t5-small")
 
 
 
 
 
 
 
6
 
7
+ # Define the function to generate website code
8
+ def generate_website(prompt):
9
+ # Instruction prompt to ensure web-style code output
10
+ full_prompt = f"Generate a modern HTML, CSS, and JavaScript website. {prompt}"
11
 
12
+ result = generator(full_prompt, max_length=1024, do_sample=True)[0]['generated_text']
13
+ return result
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ # Build a simple Gradio UI
16
+ gr.Interface(
17
+ fn=generate_website,
18
+ inputs=gr.Textbox(label="Describe the website you want", placeholder="e.g. A modern cafe website using beige and brown colors..."),
19
+ outputs=gr.Textbox(label="Generated Website Code"),
20
+ title="AI Website Code Generator",
21
+ description="Enter a prompt to generate a full website (HTML/CSS/JS)."
22
+ ).launch()