ilang / app.py
ilangai's picture
Fix: POST /compress endpoint, simplify dependencies
bf590af
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()