Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import random
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import joblib
|
| 7 |
+
|
| 8 |
+
# === Setup Logging ===
|
| 9 |
+
logging.basicConfig(
|
| 10 |
+
level=logging.INFO,
|
| 11 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
| 12 |
+
handlers=[
|
| 13 |
+
logging.FileHandler("text_to_image.log"),
|
| 14 |
+
logging.StreamHandler()
|
| 15 |
+
]
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# === Load Model ===
|
| 19 |
+
def load_model(model_path="model.pkl"):
|
| 20 |
+
try:
|
| 21 |
+
if not os.path.exists(model_path):
|
| 22 |
+
raise FileNotFoundError(f"Model not found at: {model_path}")
|
| 23 |
+
model = joblib.load(model_path)
|
| 24 |
+
logging.info("✅ Model loaded successfully.")
|
| 25 |
+
return model
|
| 26 |
+
except Exception as e:
|
| 27 |
+
logging.error(f"❌ Failed to load model: {e}")
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
# Dummy placeholder function (replace with actual inference)
|
| 31 |
+
def dummy_text_to_image(prompt):
|
| 32 |
+
logging.info(f"🔍 Received prompt: {prompt}")
|
| 33 |
+
img = Image.new("RGB", (256, 256), (
|
| 34 |
+
random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
| 35 |
+
)
|
| 36 |
+
logging.info("🖼️ Returning dummy image.")
|
| 37 |
+
return img
|
| 38 |
+
|
| 39 |
+
model = load_model()
|
| 40 |
+
|
| 41 |
+
# === Gradio Interface ===
|
| 42 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 43 |
+
gr.Markdown("## 🖼️ Text to Image Generator - Minimal (Light Mode)")
|
| 44 |
+
prompt = gr.Textbox(placeholder="Enter your prompt here", label="Prompt")
|
| 45 |
+
output = gr.Image(label="Generated Image", type="pil")
|
| 46 |
+
generate = gr.Button("Generate")
|
| 47 |
+
|
| 48 |
+
generate.click(fn=dummy_text_to_image, inputs=prompt, outputs=output)
|
| 49 |
+
|
| 50 |
+
demo.launch()
|