Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py - Jekyll Master AI Demo
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 5 |
+
import warnings
|
| 6 |
+
warnings.filterwarnings("ignore")
|
| 7 |
+
|
| 8 |
+
# ================= CONFIGURATION =================
|
| 9 |
+
MODEL_ID = "daffaaditya/jekyll-master-ai" # Model Anda yang sudah diupload
|
| 10 |
+
|
| 11 |
+
print("=" * 60)
|
| 12 |
+
print("π Jekyll Master AI - Live Demo")
|
| 13 |
+
print(f"π¦ Using model: {MODEL_ID}")
|
| 14 |
+
print("=" * 60)
|
| 15 |
+
|
| 16 |
+
# ================= LOAD MODEL =================
|
| 17 |
+
@gr.cache_resource
|
| 18 |
+
def load_model():
|
| 19 |
+
"""Load model dengan caching"""
|
| 20 |
+
print("π₯ Loading model...")
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
# Load tokenizer dan model langsung dari repo Anda
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 25 |
+
MODEL_ID,
|
| 26 |
+
trust_remote_code=True
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Load model dengan quantization untuk hemat memory
|
| 30 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 31 |
+
MODEL_ID,
|
| 32 |
+
torch_dtype=torch.float16,
|
| 33 |
+
device_map="auto",
|
| 34 |
+
trust_remote_code=True,
|
| 35 |
+
low_cpu_mem_usage=True
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
print("β
Model loaded successfully!")
|
| 39 |
+
print(f"π± Device: {model.device}")
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f"β Error loading model: {e}")
|
| 43 |
+
print("π Using fallback mode...")
|
| 44 |
+
|
| 45 |
+
# Fallback untuk testing
|
| 46 |
+
tokenizer = None
|
| 47 |
+
model = None
|
| 48 |
+
|
| 49 |
+
return tokenizer, model
|
| 50 |
+
|
| 51 |
+
# Load model
|
| 52 |
+
tokenizer, model = load_model()
|
| 53 |
+
|
| 54 |
+
# ================= GENERATION FUNCTION =================
|
| 55 |
+
def generate_jekyll_code(instruction, max_tokens=500, temperature=0.7):
|
| 56 |
+
"""Generate Jekyll code"""
|
| 57 |
+
try:
|
| 58 |
+
print(f"\nπ₯ Instruction: {instruction[:50]}...")
|
| 59 |
+
|
| 60 |
+
# Jika model tidak loaded, beri contoh
|
| 61 |
+
if model is None or tokenizer is None:
|
| 62 |
+
return f"""# Jekyll Master AI - Example Output
|
| 63 |
+
|
| 64 |
+
# Model is loading or in fallback mode
|
| 65 |
+
# Here's an example _config.yml for a tech blog:
|
| 66 |
+
|
| 67 |
+
title: "Tech Blog"
|
| 68 |
+
description: "A blog about technology and programming"
|
| 69 |
+
baseurl: ""
|
| 70 |
+
url: "https://yourblog.com"
|
| 71 |
+
theme: minima
|
| 72 |
+
|
| 73 |
+
markdown: kramdown
|
| 74 |
+
permalink: pretty
|
| 75 |
+
|
| 76 |
+
author:
|
| 77 |
+
name: "Your Name"
|
| 78 |
+
email: "you@example.com"
|
| 79 |
+
|
| 80 |
+
plugins:
|
| 81 |
+
- jekyll-feed
|
| 82 |
+
- jekyll-seo-tag
|
| 83 |
+
|
| 84 |
+
# Try the live demo when model is fully loaded
|