File size: 1,794 Bytes
2cc7027
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from src import requests

def respond_stream(
    message,
    chat_history,
    api_key,
    model,
    temperature,
    top_p,
    max_tokens,
    system,
):
    response = ""
    received_anything = False
    for chunk in requests.get_stream_chat_completion(
        message=message,
        chat_history=chat_history,
        model=model,
        api_key=api_key,
        temperature=temperature,
        top_p=top_p,
        max_tokens=int(max_tokens),
        system=system if system else None,
    ):
        response += chunk
        yield response
        received_anything = True
    if not received_anything:
        gr.Warning("Error: Invalid API Key")
        yield ""

css = """
.header-text p {line-height: 80px !important; text-align: left; font-size: 26px;}
.header-logo {text-align: left}
"""

with gr.Blocks(title="Mistral Playground") as mistral_playground:
    with gr.Row():
        api_key = gr.Textbox(lines=1, label="Mistral API Key")
        model = gr.Radio(
            choices=["mistral-tiny", "mistral-small", "mistral-medium"],
            value="mistral-tiny",
        )
    with gr.Row():
        temperature = gr.Slider(minimum=0.01, maximum=1.0, value=0.2, step=0.1, label="Temperature")
        top_p = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, label="Top P")
        max_tokens = gr.Slider(minimum=1, maximum=16000, step=500, label="Max Tokens", value=4000)

    with gr.Row():
        system = gr.Textbox(lines=10, label="System Message")
        gr.ChatInterface(
            respond_stream,
            additional_inputs=[
                api_key,
                model,
                temperature,
                top_p,
                max_tokens,
                system,
            ],
        )

mistral_playground.launch()