daffaaditya commited on
Commit
1ccae3b
Β·
verified Β·
1 Parent(s): d497f42

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
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