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