Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Initialize models
|
| 6 |
+
text_generator = pipeline("text-generation", model="gpt2")
|
| 7 |
+
image_captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 8 |
+
|
| 9 |
+
def generate_content():
|
| 10 |
+
# Generate text content
|
| 11 |
+
text_prompt = "This website is unique because"
|
| 12 |
+
generated_text = text_generator(text_prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
| 13 |
+
|
| 14 |
+
# Generate a random color for demonstration purposes
|
| 15 |
+
color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
|
| 16 |
+
|
| 17 |
+
# For now, we'll just return a placeholder for the image
|
| 18 |
+
image_description = "A placeholder for a generated image"
|
| 19 |
+
|
| 20 |
+
html_content = f"""
|
| 21 |
+
<div style="background-color: {color}; padding: 20px; border-radius: 10px;">
|
| 22 |
+
<h2>Welcome to Your Dynamic AI Website!</h2>
|
| 23 |
+
<p>{generated_text}</p>
|
| 24 |
+
<p><em>Image concept: {image_description}</em></p>
|
| 25 |
+
</div>
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
return html_content
|
| 29 |
+
|
| 30 |
+
# Create Gradio interface
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=generate_content,
|
| 33 |
+
inputs=[],
|
| 34 |
+
outputs=gr.HTML(),
|
| 35 |
+
title="AI-Driven Dynamic Website",
|
| 36 |
+
description="Click the button to generate new content!",
|
| 37 |
+
theme="huggingface"
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch the app
|
| 41 |
+
iface.launch()
|