import gradio as gr from huggingface_hub import InferenceClient import os # --- DIXARS TECHNOLOGY CONFIG --- MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3" # Safety check for the token to prevent startup crashes HF_TOKEN = os.environ.get("HF_TOKEN", "") # --- THEME --- dixars_theme = gr.themes.Soft(primary_hue="blue", secondary_hue="slate") # --- LOGIC --- def handle_login(user, pwd): if user == "admin" and pwd == "dixars2026": return gr.update(visible=False), gr.update(visible=True) return gr.update(visible=True), gr.update(visible=False) def skip_login(): return gr.update(visible=False), gr.update(visible=True) def respond(message, history, system_message, max_tokens, temperature, top_p): if not HF_TOKEN: yield "❌ SYSTEM ERROR: HF_TOKEN is missing. Please add it to Space Secrets." return try: client = InferenceClient(model=MODEL_ID, token=HF_TOKEN) messages = [{"role": "system", "content": system_message}] for user_msg, assistant_msg in history: if user_msg: messages.append({"role": "user", "content": user_msg}) if assistant_msg: messages.append({"role": "assistant", "content": assistant_msg}) messages.append({"role": "user", "content": message}) response = "" # Updated for high compatibility with Mistral v0.3 for msg in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p ): token = msg.choices[0].delta.content if token: response += token yield response except Exception as e: yield f"⚠️ DIXARS OS RUNTIME ERROR: {str(e)}" # --- UI --- with gr.Blocks(theme=dixars_theme, title="Dixars Tech Intelligence") as dixars: # LOGIN SCREEN with gr.Column(visible=True) as login_screen: gr.Markdown("# 💎 DIXARS TECHNOLOGY\n### Enterprise AI Terminal") user_input = gr.Textbox(label="Admin Username") pass_input = gr.Textbox(label="Admin Password", type="password") with gr.Row(): login_btn = gr.Button("Secure Login", variant="primary") skip_btn = gr.Button("Skip to Guest Access") # MAIN APP with gr.Column(visible=False) as main_app: gr.Markdown("## 💎 DIXARS TECHNOLOGY OS v1.0") with gr.Tabs(): with gr.Tab("💬 AI Workspace"): # Side parameters with gr.Row(): with gr.Column(scale=1): sys_msg = gr.Textbox(value="You are a Dixars Tech AI.", label="System Persona") tokens = gr.Slider(1, 4096, 1024, label="Max Tokens") temp = gr.Slider(0.1, 2.0, 0.7, label="Temperature") top_p = gr.Slider(0.1, 1.0, 0.9, label="Top-p") # Chat Interface with gr.Column(scale=3): gr.ChatInterface( respond, additional_inputs=[sys_msg, tokens, temp, top_p], ) # BUTTON ACTIONS login_btn.click(handle_login, [user_input, pass_input], [login_screen, main_app]) skip_btn.click(skip_login, None, [login_screen, main_app]) if __name__ == "__main__": dixars.launch()