Spaces:
Sleeping
Sleeping
File size: 1,618 Bytes
546b69d c4022f1 546b69d | 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 | import gradio as gr
import requests
import os
# Retrieve secrets from the Hugging Face environment
ACCOUNT_ID = os.environ.get("49fcc4d255c593469b96db6cfd3b8274")
API_TOKEN = os.environ.get("cfut_YbbCl5maJonPTdEjk27VQ3ilIPko4yVimqTQi9v1bcd1fd1d")
# We will use Llama-3 as the initial reasoning engine for testing
MODEL = "@cf/meta/llama-3.1-8b-instruct"
def ikm_reasoning_test(user_input):
if not ACCOUNT_ID or not API_TOKEN:
return "System Error: Cloudflare credentials not found in environment variables."
url = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/{MODEL}"
headers = {
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}
# This payload is simple now, but will eventually be fed by the Knowledge Aggregator
payload = {
"prompt": user_input
}
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
data = response.json()
return data["result"]["response"]
except Exception as e:
return f"API Communication Error: {str(e)}"
# User Interaction System - Phase 1 Interface
demo = gr.Interface(
fn=ikm_reasoning_test,
inputs=gr.Textbox(lines=4, placeholder="Enter a command to test the IKM Reasoning Engine..."),
outputs=gr.Textbox(label="IKM Response"),
title="Emalawi19 Intelligent Knowledge Model (IKM)",
description="Phase 1: Establishing the core AI connection and basic User Interaction System.",
theme=gr.themes.Soft()
)
if __name__ == "__main__":
demo.launch() |