Spaces:
Runtime error

File size: 3,469 Bytes
ab3c149
 
a1307c4
ab3c149
6f27c6b
a21a801
6f27c6b
 
f38c903
6f27c6b
 
ab3c149
a21a801
 
 
6f27c6b
 
a21a801
 
6f27c6b
a21a801
 
6f27c6b
 
 
a1307c4
a21a801
6f27c6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1307c4
 
 
ff5aafd
 
6f27c6b
ab3c149
6f27c6b
 
a21a801
6f27c6b
 
 
 
 
f38c903
6f27c6b
 
ab3c149
6f27c6b
a21a801
6f27c6b
 
a21a801
6f27c6b
 
a21a801
 
6f27c6b
 
 
 
a21a801
6f27c6b
a21a801
 
 
 
 
 
6f27c6b
 
 
a21a801
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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()