File size: 1,770 Bytes
fbebf66
dde614e
fbebf66
70f8d75
 
fbebf66
 
70f8d75
 
dde614e
 
 
fbebf66
dde614e
 
 
 
 
 
fbebf66
70f8d75
 
 
 
 
 
cb9d075
fbebf66
 
dde614e
 
70f8d75
fbebf66
 
 
 
70f8d75
fbebf66
70f8d75
 
 
 
 
fbebf66
70f8d75
fbebf66
70f8d75
b19dc43
67e38fa
 
70f8d75
 
 
 
dde614e
70f8d75
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
import gradio as gr
import torch
from src.model.him_model import HIMModel
from config.model_config import HIMConfig
from config.environment_config import EnvironmentConfig

def initialize_model():
    model_config = HIMConfig()
    env_config = EnvironmentConfig()
    device = torch.device("cuda" if torch.cuda.is_available() and env_config.device == "cuda" else "cpu")
    model = HIMModel(model_config).to(device)
    return model

def chat(message: str, 
         system_message: str = "You are a friendly Chatbot.",
         max_tokens: int = 512,
         temperature: float = 0.7,
         top_p: float = 0.95):
    
    input_data = {
        "message": message,
        "system_message": system_message,
        "parameters": {
            "max_tokens": max_tokens,
            "temperature": temperature,
            "top_p": top_p
        }
    }
    
    with torch.no_grad():
        result = model.generate_response(input_data)
    return result["response"]

model = initialize_model()

interface = gr.Interface(
    fn=chat,
    inputs=[
        gr.Textbox(label="Message"),
        gr.Textbox(label="System Message", value="You are a friendly Chatbot."),
        gr.Slider(minimum=1, maximum=2048, value=512, label="Max Tokens"),
        gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Temperature"),
        gr.Slider(minimum=0.1, maximum=1.0, value=0.95, label="Top P")
    ],
    outputs=gr.Textbox(label="HIM Response"),
    title="Hybrid Intelligence Matrix (HIM)",
    description="Interact with the HIM system for advanced cognitive processing"
)

if __name__ == "__main__":
    env_config = EnvironmentConfig()
    interface.launch(
        server_name=env_config.api_host,
        server_port=env_config.api_port,
        share=True
    )