File size: 1,674 Bytes
dcc71b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import hashlib
from datetime import datetime
import os

IRIN_PREFIX = "10.25834/bibliox"
COUNTER_FILE = "counter.txt"

def get_next_id():
    if os.path.exists(COUNTER_FILE):
        with open(COUNTER_FILE, 'r') as f:
            counter = int(f.read())
    else:
        counter = 0
    counter += 1
    with open(COUNTER_FILE, 'w') as f:
        f.write(str(counter))
    return counter

def generate_irin(title):
    """
    輸入標題 → 生成IRIN
    """
    if not title:
        return "❌ Please enter a paper title"
    
    # 算Hash
    fmc_hash = hashlib.sha256(title.encode('utf-8')).hexdigest()[:16]
    
    # 生成IRIN
    paper_id = get_next_id()
    year = datetime.now().year
    irin = f"{IRIN_PREFIX}.{year}.{paper_id:05d}"
    pub_date = datetime.now().strftime('%B %d, %Y')
    
    # 回傳結果
    result = f"""
## ✅ IRIN Generated!

**IRIN:** `{irin}`  
**Date:** {pub_date}  
**Hash:** `{fmc_hash}`  
**Status:** ✅ Certified

---

**Copy this IRIN and paste it into your Wix blog post!**
"""
    return result

# === Gradio UI ===
with gr.Blocks(theme=gr.themes.Soft()) as app:
    gr.Markdown("# 🔬 IRIN Generator")
    
    with gr.Row():
        title_input = gr.Textbox(
            label="Paper Title",
            placeholder="Enter your paper title...",
            scale=3
        )
        generate_btn = gr.Button("🚀 Generate", scale=1, variant="primary")
    
    output = gr.Markdown(value="Enter a title and click Generate")
    
    generate_btn.click(
        fn=generate_irin,
        inputs=title_input,
        outputs=output
    )
    
    gr.Markdown("**Powered by BiblioX**")

app.launch()