Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,145 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
import torch
|
| 4 |
import json
|
| 5 |
from pathlib import Path
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
def main():
|
| 35 |
-
st.set_page_config(page_title="Fast Web
|
| 36 |
|
| 37 |
-
st.title("
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
tokenizer, model = load_model()
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
-
|
| 59 |
-
with col2:
|
| 60 |
-
st.subheader("Quick Settings")
|
| 61 |
-
use_tailwind = st.checkbox("Use Tailwind CSS", value=True)
|
| 62 |
-
responsive = st.checkbox("Make Responsive", value=True)
|
| 63 |
-
dark_mode = st.checkbox("Add Dark Mode", value=False)
|
| 64 |
-
|
| 65 |
-
if st.button("🚀 Generate Code"):
|
| 66 |
-
with st.spinner("Generating your code..."):
|
| 67 |
-
# Construct prompt based on settings
|
| 68 |
-
prompt_template = f"""
|
| 69 |
-
Create a website with these specifications:
|
| 70 |
-
Description: {description}
|
| 71 |
-
CSS Framework: {"Tailwind" if use_tailwind else "Plain CSS"}
|
| 72 |
-
Features: {"Responsive, " if responsive else ""}{"Dark mode, " if dark_mode else ""}
|
| 73 |
-
|
| 74 |
-
Generate the code:
|
| 75 |
-
"""
|
| 76 |
-
|
| 77 |
-
generated_code = generate_code(model, tokenizer, prompt_template)
|
| 78 |
-
|
| 79 |
-
# Display code
|
| 80 |
-
st.code(generated_code, language="html")
|
| 81 |
-
|
| 82 |
-
# Add download button
|
| 83 |
-
st.download_button(
|
| 84 |
-
"📥 Download Code",
|
| 85 |
-
generated_code,
|
| 86 |
-
file_name="generated_website.html",
|
| 87 |
-
mime="text/html"
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
# Add helpful tips
|
| 91 |
-
with st.expander("💡 Tips for better results"):
|
| 92 |
-
st.markdown("""
|
| 93 |
-
- Be specific in your description
|
| 94 |
-
- Mention key features you want
|
| 95 |
-
- Specify color schemes if important
|
| 96 |
-
- Describe the layout structure
|
| 97 |
-
""")
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
|
|
|
| 3 |
import json
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
+
# Pre-defined components and templates
|
| 7 |
+
COMPONENTS = {
|
| 8 |
+
"navbar": """
|
| 9 |
+
<nav class="bg-white shadow">
|
| 10 |
+
<div class="max-w-7xl mx-auto px-4">
|
| 11 |
+
<div class="flex justify-between h-16">
|
| 12 |
+
<div class="flex">
|
| 13 |
+
<div class="flex-shrink-0 flex items-center">
|
| 14 |
+
<a href="/" class="text-xl font-bold">Logo</a>
|
| 15 |
+
</div>
|
| 16 |
+
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
|
| 17 |
+
<a href="#" class="text-gray-900 inline-flex items-center px-1 pt-1">Home</a>
|
| 18 |
+
<a href="#" class="text-gray-500 hover:text-gray-900 inline-flex items-center px-1 pt-1">About</a>
|
| 19 |
+
<a href="#" class="text-gray-500 hover:text-gray-900 inline-flex items-center px-1 pt-1">Services</a>
|
| 20 |
+
<a href="#" class="text-gray-500 hover:text-gray-900 inline-flex items-center px-1 pt-1">Contact</a>
|
| 21 |
+
</div>
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
</div>
|
| 25 |
+
</nav>
|
| 26 |
+
""",
|
| 27 |
+
"hero": """
|
| 28 |
+
<div class="relative bg-white overflow-hidden">
|
| 29 |
+
<div class="max-w-7xl mx-auto">
|
| 30 |
+
<div class="relative z-10 pb-8 bg-white sm:pb-16 md:pb-20 lg:max-w-2xl lg:w-full lg:pb-28 xl:pb-32">
|
| 31 |
+
<main class="mt-10 mx-auto max-w-7xl px-4 sm:mt-12 sm:px-6 md:mt-16 lg:mt-20 lg:px-8 xl:mt-28">
|
| 32 |
+
<div class="sm:text-center lg:text-left">
|
| 33 |
+
<h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:text-6xl">
|
| 34 |
+
<span class="block xl:inline">Your Awesome</span>
|
| 35 |
+
<span class="block text-indigo-600 xl:inline">Website Title</span>
|
| 36 |
+
</h1>
|
| 37 |
+
<p class="mt-3 text-base text-gray-500 sm:mt-5 sm:text-lg sm:max-w-xl sm:mx-auto md:mt-5 md:text-xl lg:mx-0">
|
| 38 |
+
Your compelling description goes here.
|
| 39 |
+
</p>
|
| 40 |
+
<div class="mt-5 sm:mt-8 sm:flex sm:justify-center lg:justify-start">
|
| 41 |
+
<div class="rounded-md shadow">
|
| 42 |
+
<a href="#" class="w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 md:py-4 md:text-lg md:px-10">
|
| 43 |
+
Get Started
|
| 44 |
+
</a>
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
</main>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
""",
|
| 53 |
+
"features": """
|
| 54 |
+
<div class="py-12 bg-white">
|
| 55 |
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
| 56 |
+
<div class="grid grid-cols-1 gap-8 sm:grid-cols-2 lg:grid-cols-3">
|
| 57 |
+
<!-- Feature 1 -->
|
| 58 |
+
<div class="p-6 border rounded-lg">
|
| 59 |
+
<h3 class="text-lg font-medium text-gray-900">Feature 1</h3>
|
| 60 |
+
<p class="mt-2 text-base text-gray-500">Description of feature 1</p>
|
| 61 |
+
</div>
|
| 62 |
+
<!-- Feature 2 -->
|
| 63 |
+
<div class="p-6 border rounded-lg">
|
| 64 |
+
<h3 class="text-lg font-medium text-gray-900">Feature 2</h3>
|
| 65 |
+
<p class="mt-2 text-base text-gray-500">Description of feature 2</p>
|
| 66 |
+
</div>
|
| 67 |
+
<!-- Feature 3 -->
|
| 68 |
+
<div class="p-6 border rounded-lg">
|
| 69 |
+
<h3 class="text-lg font-medium text-gray-900">Feature 3</h3>
|
| 70 |
+
<p class="mt-2 text-base text-gray-500">Description of feature 3</p>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
"""
|
| 76 |
+
}
|
| 77 |
|
| 78 |
+
def generate_website():
|
| 79 |
+
# Base HTML template with Tailwind CSS
|
| 80 |
+
html_template = """
|
| 81 |
+
<!DOCTYPE html>
|
| 82 |
+
<html lang="en">
|
| 83 |
+
<head>
|
| 84 |
+
<meta charset="UTF-8">
|
| 85 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 86 |
+
<title>{title}</title>
|
| 87 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 88 |
+
</head>
|
| 89 |
+
<body>
|
| 90 |
+
{components}
|
| 91 |
+
</body>
|
| 92 |
+
</html>
|
| 93 |
+
"""
|
| 94 |
+
return html_template
|
| 95 |
|
| 96 |
def main():
|
| 97 |
+
st.set_page_config(page_title="Fast Web Builder", layout="wide")
|
| 98 |
|
| 99 |
+
st.title("🚀 Fast Web Builder")
|
| 100 |
|
| 101 |
+
# Simple configuration
|
| 102 |
+
title = st.text_input("Website Title", "My Awesome Website")
|
|
|
|
| 103 |
|
| 104 |
+
# Component selection
|
| 105 |
+
st.subheader("Select Components")
|
| 106 |
+
use_navbar = st.checkbox("Navigation Bar", value=True)
|
| 107 |
+
use_hero = st.checkbox("Hero Section", value=True)
|
| 108 |
+
use_features = st.checkbox("Features Section", value=True)
|
| 109 |
|
| 110 |
+
# Color scheme
|
| 111 |
+
color_scheme = st.selectbox(
|
| 112 |
+
"Color Scheme",
|
| 113 |
+
["Default", "Dark", "Light", "Colorful"]
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
if st.button("Generate Website"):
|
| 117 |
+
# Build components string
|
| 118 |
+
components = ""
|
| 119 |
+
if use_navbar:
|
| 120 |
+
components += COMPONENTS["navbar"]
|
| 121 |
+
if use_hero:
|
| 122 |
+
components += COMPONENTS["hero"]
|
| 123 |
+
if use_features:
|
| 124 |
+
components += COMPONENTS["features"]
|
| 125 |
+
|
| 126 |
+
# Generate complete website
|
| 127 |
+
website = generate_website().format(
|
| 128 |
+
title=title,
|
| 129 |
+
components=components
|
| 130 |
)
|
| 131 |
|
| 132 |
+
# Show preview
|
| 133 |
+
st.subheader("Preview")
|
| 134 |
+
st.components.v1.html(website, height=600)
|
| 135 |
+
|
| 136 |
+
# Download option
|
| 137 |
+
st.download_button(
|
| 138 |
+
"Download Website",
|
| 139 |
+
website,
|
| 140 |
+
file_name="website.html",
|
| 141 |
+
mime="text/html"
|
| 142 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
if __name__ == "__main__":
|
| 145 |
main()
|