File size: 3,709 Bytes
72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee bf590af 72575ee | 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 | import gradio as gr
import requests
import json
API_URL = "https://api.ilang.ai/compress"
def compress(text, ratio):
if not text.strip():
return "", ""
try:
resp = requests.post(API_URL, json={"input": text}, headers={"Content-Type": "application/json"}, timeout=30)
if resp.status_code == 200:
data = resp.json()
tokens = data.get("tokens", {})
return data.get("output", ""), f"{tokens.get('input','?')} -> {tokens.get('output','?')} tokens ({tokens.get('saved','?')} saved)"
elif resp.status_code == 429:
return resp.json().get("error", "Rate limited"), ""
else:
return resp.json().get("error", f"API error {resp.status_code}"), ""
except Exception as e:
return f"Connection error: {e}", ""
def decompress(ilang_text):
if not ilang_text.strip():
return ""
try:
resp = requests.post(API_URL, json={"input": f"Expand this I-Lang back to clear natural English. Output ONLY natural language:\n\n{ilang_text}"}, headers={"Content-Type": "application/json"}, timeout=30)
if resp.status_code == 200:
return resp.json().get("output", "")
return f"API error {resp.status_code}"
except Exception as e:
return f"Connection error: {e}"
with gr.Blocks(title="I-Lang Protocol", theme=gr.themes.Base()) as demo:
gr.Markdown("# I-Lang: AI Communication Protocol\n**Compress natural language into structured, machine-readable instructions.**\n\n52 verbs | Pipe syntax | 40-65% token savings\n\n[GitHub](https://github.com/ilang-ai) | [Spec](https://github.com/ilang-ai/ilang-spec) | [Dictionary](https://github.com/ilang-ai/ilang-dict) | [Training Data](https://huggingface.co/datasets/i-Lang/ilang-instruction-corpus) | [Paper](https://doi.org/10.13140/RG.2.2.22821.97762)")
with gr.Tab("Compress"):
with gr.Row():
with gr.Column():
input_text = gr.Textbox(label="Natural Language", placeholder="Describe a task, workflow, or image...", lines=5)
compress_btn = gr.Button("Compress to I-Lang", variant="primary")
with gr.Column():
output_text = gr.Textbox(label="I-Lang Output", lines=5, show_copy_button=True)
savings_text = gr.Textbox(label="Token Savings", interactive=False)
compress_btn.click(compress, inputs=[input_text], outputs=[output_text, savings_text])
gr.Examples(examples=[["Read all customer feedback, filter negative sentiment, group by product, count issues, rank by frequency, export CSV."],["Read README from GitHub, translate to Chinese, save to cloud storage."],["Scrape Hacker News, filter AI posts, summarize top 5, format as markdown table."],["Create a cyberpunk cityscape at night with neon lights and rain reflections."]], inputs=[input_text])
with gr.Tab("Expand"):
with gr.Row():
with gr.Column():
ilang_input = gr.Textbox(label="I-Lang Input", placeholder="Paste I-Lang notation...", lines=5)
expand_btn = gr.Button("Expand to Natural Language", variant="primary")
with gr.Column():
expanded_output = gr.Textbox(label="Natural Language", lines=5, show_copy_button=True)
expand_btn.click(decompress, inputs=[ilang_input], outputs=[expanded_output])
gr.Examples(examples=[["[READ:@GH|path=readme.md]=>[TRANSLATE|lang=zh]=>[FMT|fmt=md]=>[WRITE:@R2]"],["[SCAN:@FILE|type=deps]=>[CHECK|type=security]=>[FILT|key=critical]=>[ALERT]=>[LOG]"]], inputs=[ilang_input])
gr.Markdown("---\nI-Lang v2.0 | [Palm Media Technology](https://ilang.ai)")
if __name__ == "__main__":
demo.launch()
|