Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Configuration
|
| 6 |
+
INVOKE_URL = "https://integrate.api.nvidia.com/v1/chat/completions"
|
| 7 |
+
API_KEY = "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"
|
| 8 |
+
|
| 9 |
+
def predict(message, history):
|
| 10 |
+
headers = {
|
| 11 |
+
"Authorization": f"Bearer {API_KEY}",
|
| 12 |
+
"Accept": "text/event-stream"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
payload = {
|
| 16 |
+
"model": "moonshotai/kimi-k2.6",
|
| 17 |
+
"messages": [{"role": "user", "content": message}],
|
| 18 |
+
"max_tokens": 16384,
|
| 19 |
+
"temperature": 1.0,
|
| 20 |
+
"stream": True,
|
| 21 |
+
"chat_template_kwargs": {"thinking": True}, # 🔱 Inachi Thinking Mode
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
response = requests.post(INVOKE_URL, headers=headers, json=payload, stream=True)
|
| 25 |
+
|
| 26 |
+
partial_message = ""
|
| 27 |
+
for line in response.iter_lines():
|
| 28 |
+
if line:
|
| 29 |
+
# Decode the event-stream line
|
| 30 |
+
line = line.decode("utf-8")
|
| 31 |
+
if line.startswith("data: "):
|
| 32 |
+
data_str = line[6:]
|
| 33 |
+
if data_str == "[DONE]":
|
| 34 |
+
break
|
| 35 |
+
try:
|
| 36 |
+
data_json = json.loads(data_str)
|
| 37 |
+
# Check if 'choices' exists and has content
|
| 38 |
+
delta = data_json['choices'][0]['delta']
|
| 39 |
+
if 'content' in delta:
|
| 40 |
+
content = delta['content']
|
| 41 |
+
partial_message += content
|
| 42 |
+
yield partial_message
|
| 43 |
+
except:
|
| 44 |
+
continue
|
| 45 |
+
|
| 46 |
+
# 🔱 Inachi UI Styling
|
| 47 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate")) as demo:
|
| 48 |
+
gr.Markdown("# 🔱 INACHI V1.1 - Kimi-k2.6 Experimental Lab")
|
| 49 |
+
gr.Markdown("Testing NVIDIA MoonshotAI with **Thinking Mode** enabled.")
|
| 50 |
+
|
| 51 |
+
chat = gr.ChatInterface(
|
| 52 |
+
fn=predict,
|
| 53 |
+
title="Inachi Core Testing",
|
| 54 |
+
description="Master Architect MINZO-PRIME, the system is ready for testing."
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
demo.launch()
|