File size: 2,145 Bytes
a287034
9b5859a
 
 
cb4365c
9b5859a
 
72a6125
9b5859a
 
 
 
 
 
 
027d7ea
cc7765a
9b5859a
cc7765a
9b5859a
 
cc7765a
 
9b5859a
cc7765a
9b5859a
 
 
 
 
 
 
 
 
cc7765a
9b5859a
 
cc7765a
 
 
9b5859a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63fcd71
9b5859a
cc7765a
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
import gradio as gr
from huggingface_hub import InferenceClient
import os
import ssl

# Ensure SSL module is available
ssl._create_default_https_context = ssl._create_unverified_context

# Load Hugging Face API Token from Environment Variables
HF_TOKEN = os.getenv("HF_TOKEN")

# Initialize Mistral-7B Model
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1", token=HF_TOKEN)

# Function to handle chat
def respond(message, history):
    messages = []
    
    for user_msg, bot_msg in history:
        if user_msg:
            messages.append({"role": "user", "content": user_msg})
        if bot_msg:
            messages.append({"role": "assistant", "content": bot_msg})

    messages.append({"role": "user", "content": message})

    response = ""
    chat_response = client.chat_completion(
        messages,
        max_tokens=512,  # Default max tokens
        stream=False,  # Change to True if streaming works
        temperature=0.7,  # Default temperature
        top_p=0.95,  # Default top-p value
    )
    
    if hasattr(chat_response, "choices") and chat_response.choices:
        response = chat_response.choices[0].message.content
    
    return response

# Custom Styling for Dark Mode
custom_css = """
body {
    background-color: #121212;
    color: white;
    font-family: 'Arial', sans-serif;
}
.gradio-container {
    max-width: 700px;
    margin: auto;
    padding: 20px;
    background: #1E1E1E;
    border-radius: 10px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
}
h1 {
    font-size: 24px;
    font-weight: bold;
    text-align: left;
    color: #00ccff;
}
h2 {
    text-align: center;
    font-size: 30px;
    font-weight: bold;
    color: white;
}
.watermark {
    text-align: center;
    font-size: 14px;
    color: gray;
    margin-top: 20px;
}
"""

# Gradio Chat Interface
with gr.Blocks(css=custom_css) as demo:
    gr.Markdown("<h1>Mistral AI Chatbot</h1>")  # Top left title
    gr.Markdown("<h2>How can I help you?</h2>")  # Center title

    chatbot = gr.ChatInterface(respond)
    
    gr.Markdown('<div class="watermark">Created by Rajma</div>')

if _name_ == "_main_":
    demo.launch()