import gradio as gr
import json
import pyodide.http
async def predict(message, history, system_prompt):
messages = [{"role": "system", "content": system_prompt}]
for user_msg, assistant_msg in history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": assistant_msg})
messages.append({"role": "user", "content": message})
url = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-7B-Instruct/v1/chat/completions"
headers = {
"Content-Type": "application/json"
}
body = json.dumps({
"model": "Qwen/Qwen2.5-7B-Instruct",
"messages": messages,
"max_tokens": 500
})
try:
response = await pyodide.http.pyfetch(url, method="POST", headers=headers, body=body)
data = await response.json()
if "error" in data:
return f"API Error: {data['error']}. (You may need to add a free HF API token if rate limited)."
return data["choices"][0]["message"]["content"]
except Exception as e:
return f"Connection Error: {str(e)}"
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# 🚀 Skyvault GPU Core | Enterprise AI Portal")
gr.Markdown("Secure cloud compute and high-performance AI inference engine running 24/7.")
with gr.Row():
with gr.Column(scale=1):
system_prompt = gr.Textbox(
label="System Prompt / Personality",
value="You are Skyvault AI, a high-performance corporate assistant built for global enterprise workloads.",
lines=3
)
gr.Markdown("### 🔑 API Access Status")
gr.Info("Connected to 24/7 Global Serverless Routing Layer.")
with gr.Column(scale=3):
gr.ChatInterface(
fn=predict,
additional_inputs=[system_prompt],
title="Live Model Studio"
)
demo.launch()