ilangai commited on
Commit
72575ee
·
1 Parent(s): 1fa56d9

Initial release: I-Lang protocol converter

Browse files
Files changed (3) hide show
  1. README.md +44 -6
  2. app.py +148 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,14 +1,52 @@
1
  ---
2
- title: Ilang
3
  emoji: ⚡
4
- colorFrom: purple
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 6.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: Compress natural language to structured AI instructions.
 
 
 
 
 
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: I-Lang Protocol
3
  emoji: ⚡
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: "5.0"
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ short_description: Compress natural language to structured AI instructions
12
+ tags:
13
+ - protocol
14
+ - compression
15
+ - ai-communication
16
+ - prompt-engineering
17
  ---
18
 
19
+ # I-Lang: AI Communication Protocol
20
+
21
+ Compress natural language into structured, machine-readable instructions using the I-Lang protocol.
22
+
23
+ ## What is I-Lang?
24
+
25
+ I-Lang is a communication protocol for human-AI and AI-to-AI interaction. It uses 52 verbs, 28 modifiers, and 14 entities with pipe syntax to compress instructions by 40-65%.
26
+
27
+ ## Try it
28
+
29
+ 1. **Compress**: Paste any instruction or workflow description, set compression ratio, get I-Lang output
30
+ 2. **Expand**: Paste I-Lang notation, get human-readable explanation
31
+
32
+ ## Links
33
+
34
+ - [Protocol Spec](https://github.com/ilang-ai/ilang-spec)
35
+ - [Dictionary](https://github.com/ilang-ai/ilang-dict)
36
+ - [Datasets](https://huggingface.co/i-Lang)
37
+ - [Research Paper](https://doi.org/10.13140/RG.2.2.22821.97762)
38
+
39
+ ## Example
40
+
41
+ **Input:**
42
+ ```
43
+ Read the README from GitHub, translate it to Chinese, and save to cloud storage.
44
+ ```
45
+
46
+ **I-Lang (60% compression):**
47
+ ```
48
+ [READ:@GH|path=readme.md]=>[θ|lng=zh]=>[WRIT:@R2|path=readme_zh.md]
49
+ ```
50
+
51
+ ---
52
+ I-Lang v2.0 | Palm Media Technology
app.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+ import tiktoken
5
+
6
+ API_URL = "https://api.ilang.ai"
7
+
8
+ def count_tokens(text):
9
+ """Estimate token count using cl100k_base."""
10
+ try:
11
+ enc = tiktoken.get_encoding("cl100k_base")
12
+ return len(enc.encode(text))
13
+ except Exception:
14
+ return len(text.split()) * 1.3 # fallback rough estimate
15
+
16
+ def compress(text, ratio):
17
+ """Call api.ilang.ai to compress natural language to I-Lang."""
18
+ if not text.strip():
19
+ return "", "", ""
20
+
21
+ try:
22
+ resp = requests.post(
23
+ API_URL,
24
+ json={"input": text, "ratio": ratio / 100},
25
+ headers={"Content-Type": "application/json"},
26
+ timeout=30,
27
+ )
28
+ if resp.status_code == 200:
29
+ data = resp.json()
30
+ compressed = data.get("output", data.get("text", str(data)))
31
+ elif resp.status_code == 429:
32
+ return "Rate limited. Try again in a minute.", "", ""
33
+ else:
34
+ return f"API error {resp.status_code}", "", ""
35
+ except Exception as e:
36
+ return f"Connection error: {e}", "", ""
37
+
38
+ original_tokens = count_tokens(text)
39
+ compressed_tokens = count_tokens(compressed)
40
+ if original_tokens > 0:
41
+ actual_ratio = (1 - compressed_tokens / original_tokens) * 100
42
+ savings = f"{original_tokens} tokens -> {compressed_tokens} tokens ({actual_ratio:.0f}% saved)"
43
+ else:
44
+ savings = ""
45
+
46
+ return compressed, savings, f"Original: {len(text)} chars | Compressed: {len(compressed)} chars"
47
+
48
+ def decompress(ilang_text):
49
+ """Call api.ilang.ai to expand I-Lang back to natural language."""
50
+ if not ilang_text.strip():
51
+ return ""
52
+
53
+ prompt = f"Expand this I-Lang notation back to clear, natural English:\n\n{ilang_text}"
54
+ try:
55
+ resp = requests.post(
56
+ API_URL,
57
+ json={"input": prompt, "ratio": 0},
58
+ headers={"Content-Type": "application/json"},
59
+ timeout=30,
60
+ )
61
+ if resp.status_code == 200:
62
+ data = resp.json()
63
+ return data.get("output", data.get("text", str(data)))
64
+ else:
65
+ return f"API error {resp.status_code}"
66
+ except Exception as e:
67
+ return f"Connection error: {e}"
68
+
69
+ EXAMPLES = [
70
+ ["Read the README from GitHub, translate it to Chinese, and save to cloud storage.", 60],
71
+ ["Scrape Hacker News, filter AI-related posts, summarize top 5, format as markdown table, send to Telegram.", 70],
72
+ ["Check if the user's input contains sensitive content. If yes, reject with explanation. If no, process normally and log the result.", 50],
73
+ ]
74
+
75
+ with gr.Blocks(
76
+ title="I-Lang Protocol",
77
+ theme=gr.themes.Base(),
78
+ css="""
79
+ .header { text-align: center; margin-bottom: 1rem; }
80
+ .stats { font-family: monospace; color: #666; }
81
+ """
82
+ ) as demo:
83
+
84
+ gr.Markdown("""
85
+ # I-Lang: AI Communication Protocol
86
+ **Compress natural language into structured, machine-readable instructions.**
87
+
88
+ 52 verbs | 28 modifiers | 14 entities | Pipe syntax | 40-65% compression
89
+
90
+ [GitHub](https://github.com/ilang-ai) | [Spec](https://github.com/ilang-ai/ilang-spec) | [Dictionary](https://github.com/ilang-ai/ilang-dict) | [Paper](https://doi.org/10.13140/RG.2.2.22821.97762)
91
+ """)
92
+
93
+ with gr.Tab("Compress"):
94
+ with gr.Row():
95
+ with gr.Column():
96
+ input_text = gr.Textbox(
97
+ label="Natural Language",
98
+ placeholder="Describe a task, workflow, or instruction...",
99
+ lines=6,
100
+ )
101
+ ratio_slider = gr.Slider(
102
+ minimum=20, maximum=90, value=60, step=5,
103
+ label="Target Compression (%)",
104
+ info="Higher = denser output, less human-readable"
105
+ )
106
+ compress_btn = gr.Button("Compress to I-Lang", variant="primary")
107
+
108
+ with gr.Column():
109
+ output_text = gr.Textbox(label="I-Lang Output", lines=6, show_copy_button=True)
110
+ savings_text = gr.Textbox(label="Token Savings", interactive=False, elem_classes="stats")
111
+ chars_text = gr.Textbox(label="Character Count", interactive=False, elem_classes="stats")
112
+
113
+ compress_btn.click(
114
+ compress,
115
+ inputs=[input_text, ratio_slider],
116
+ outputs=[output_text, savings_text, chars_text],
117
+ )
118
+
119
+ gr.Examples(
120
+ examples=EXAMPLES,
121
+ inputs=[input_text, ratio_slider],
122
+ )
123
+
124
+ with gr.Tab("Expand"):
125
+ with gr.Row():
126
+ with gr.Column():
127
+ ilang_input = gr.Textbox(
128
+ label="I-Lang Input",
129
+ placeholder="Paste I-Lang notation here...",
130
+ lines=6,
131
+ )
132
+ expand_btn = gr.Button("Expand to Natural Language", variant="primary")
133
+ with gr.Column():
134
+ expanded_output = gr.Textbox(label="Natural Language", lines=6, show_copy_button=True)
135
+
136
+ expand_btn.click(
137
+ decompress,
138
+ inputs=[ilang_input],
139
+ outputs=[expanded_output],
140
+ )
141
+
142
+ gr.Markdown("""
143
+ ---
144
+ I-Lang v2.0 | Created by AI x Human collaboration | Palm Media Technology
145
+ """)
146
+
147
+ if __name__ == "__main__":
148
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.0
2
+ requests
3
+ tiktoken