Ai-core-os / app.py
Snapspark's picture
Update app.py
9b46195 verified
Raw
History Blame Contribute Delete
8.43 kB
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from pydantic import BaseModel
from typing import Optional, List
app = FastAPI()
class WebsiteRequest(BaseModel):
business_type: str
name: str
color: str = "blue"
logo_url: Optional[str] = ""
template: Optional[str] = "modern"
has_contact_form: Optional[bool] = True
has_ads: Optional[bool] = False
adsense_publisher_id: Optional[str] = ""
@app.get("/")
def root():
return {"status": "AI OS Core running"}
@app.post("/build-website")
def build_website(request: WebsiteRequest):
name = request.name
business = request.business_type
color = request.color
logo = request.logo_url if request.logo_url else f"https://via.placeholder.com/100x100?text={name[0]}"
# AdSense script (adds money-making ads)
adsense_script = ""
if request.has_ads and request.adsense_publisher_id:
adsense_script = f'''
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client={request.adsense_publisher_id}" crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="{request.adsense_publisher_id}"
data-ad-slot=""></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({{}});</script>
'''
# Navigation
nav = f'''
<nav style="background:#333; padding:15px 0; position:sticky; top:0; z-index:100;">
<div style="max-width:1200px; margin:auto; display:flex; justify-content:space-between; align-items:center; padding:0 20px;">
<div style="display:flex; align-items:center; gap:10px;">
<img src="{logo}" style="width:40px; height:40px; border-radius:50%;" alt="logo">
<span style="color:white; font-weight:bold; font-size:20px;">{name}</span>
</div>
<div>
<a href="#home" style="color:white; text-decoration:none; margin:0 15px;">Home</a>
<a href="#about" style="color:white; text-decoration:none; margin:0 15px;">About</a>
<a href="#services" style="color:white; text-decoration:none; margin:0 15px;">Services</a>
<a href="#contact" style="color:white; text-decoration:none; margin:0 15px;">Contact</a>
</div>
</div>
</nav>
'''
# Contact form
contact_form = '''
<form id="contactForm" style="max-width:500px; margin:20px auto;">
<input type="text" id="name" placeholder="Your Name" required style="width:100%; padding:12px; margin:10px 0; border:1px solid #ddd; border-radius:5px;">
<input type="email" id="email" placeholder="Your Email" required style="width:100%; padding:12px; margin:10px 0; border:1px solid #ddd; border-radius:5px;">
<textarea id="message" placeholder="Your Message" rows="4" style="width:100%; padding:12px; margin:10px 0; border:1px solid #ddd; border-radius:5px;"></textarea>
<button type="submit" style="background:''' + color + '''; color:white; padding:12px 30px; border:none; border-radius:5px; cursor:pointer;">Send Message</button>
</form>
<div id="formStatus" style="margin-top:10px;"></div>
<script>
document.getElementById('contactForm').addEventListener('submit', async(e) => {
e.preventDefault();
const status = document.getElementById('formStatus');
status.innerHTML = '<p style="color:green;">Sending...</p>';
setTimeout(() => {
status.innerHTML = '<p style="color:green;">✅ Message sent!</p>';
document.getElementById('contactForm').reset();
}, 1000);
});
</script>
'''
# Complete HTML
html = f'''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{name} - {business}</title>
<style>
* {{ margin:0; padding:0; box-sizing:border-box; }}
body {{ font-family: Arial, sans-serif; }}
section {{ padding: 80px 20px; text-align: center; }}
.container {{ max-width: 1200px; margin: auto; }}
.services-grid {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(280px,1fr)); gap: 30px; margin-top: 40px; }}
.service-card {{ padding: 30px; border: 1px solid #ddd; border-radius: 10px; transition: transform 0.3s; }}
.service-card:hover {{ transform: translateY(-5px); box-shadow: 0 5px 20px rgba(0,0,0,0.1); }}
html {{ scroll-behavior: smooth; }}
.ad-container {{ margin: 20px 0; text-align: center; }}
@media (max-width: 768px) {{
nav div {{ flex-direction: column; gap: 10px; }}
}}
</style>
{f'<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client={request.adsense_publisher_id}" crossorigin="anonymous"></script>' if request.has_ads and request.adsense_publisher_id else ''}
</head>
<body>
{nav}
<section id="home" style="background:{color}; color:white; min-height:60vh; display:flex; align-items:center; justify-content:center;">
<div>
<h1 style="font-size:48px; margin-bottom:20px;">Welcome to {name}</h1>
<p style="font-size:20px; margin-bottom:30px;">Your trusted partner in {business}</p>
<a href="#contact" style="background:white; color:{color}; padding:15px 30px; text-decoration:none; border-radius:8px; font-weight:bold;">Get Started</a>
</div>
</section>
{f'<div class="ad-container">{adsense_script}</div>' if request.has_ads and request.adsense_publisher_id else ''}
<section id="about" style="background:#f9f9f9;">
<div class="container">
<h2 style="color:#333; margin-bottom:20px;">About {name}</h2>
<p style="color:#666; max-width:800px; margin:auto; line-height:1.8;">We are a leading {business} company dedicated to providing high-quality services. Our team of experts ensures you get the best results possible.</p>
</div>
</section>
<section id="services">
<div class="container">
<h2 style="color:#333; margin-bottom:20px;">Our Services</h2>
<div class="services-grid">
<div class="service-card">
<h3 style="color:{color};">Premium Service</h3>
<p style="color:#666; margin-top:10px;">High-quality {business} service delivered professionally.</p>
</div>
<div class="service-card">
<h3 style="color:{color};">Expert Solutions</h3>
<p style="color:#666; margin-top:10px;">Tailored strategies for your specific needs.</p>
</div>
<div class="service-card">
<h3 style="color:{color};">24/7 Support</h3>
<p style="color:#666; margin-top:10px;">Round-the-clock assistance guaranteed.</p>
</div>
</div>
</div>
</section>
{f'<div class="ad-container">{adsense_script}</div>' if request.has_ads and request.adsense_publisher_id else ''}
<section id="contact" style="background:#f9f9f9;">
<div class="container">
<h2 style="color:#333; margin-bottom:20px;">Contact Us</h2>
<p style="color:#666; margin-bottom:30px;">Get in touch with us for any inquiries</p>
{contact_form if request.has_contact_form else f'<p>Email: info@{name.lower().replace(" ", "")}.com</p>'}
</div>
</section>
<footer style="background:#333; color:white; text-align:center; padding:20px;">
<p>&copy; 2024 {name}. All rights reserved.</p>
</footer>
</body>
</html>
'''
return {"success": True, "html": html, "business": business, "name": name}
@app.get("/test-website")
def test_website():
return HTMLResponse("<h1>✅ AI Core Working</h1><p>Website builder with AdSense is ready.</p>")