LetsChat-AI / app.py
Emalawi19's picture
Update app.py
c4022f1 verified
Raw
History Blame Contribute Delete
1.62 kB
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()