marcofrodl commited on
Commit
2cc7027
1 Parent(s): b28e11a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from src import requests
3
+
4
+ def respond_stream(
5
+ message,
6
+ chat_history,
7
+ api_key,
8
+ model,
9
+ temperature,
10
+ top_p,
11
+ max_tokens,
12
+ system,
13
+ ):
14
+ response = ""
15
+ received_anything = False
16
+ for chunk in requests.get_stream_chat_completion(
17
+ message=message,
18
+ chat_history=chat_history,
19
+ model=model,
20
+ api_key=api_key,
21
+ temperature=temperature,
22
+ top_p=top_p,
23
+ max_tokens=int(max_tokens),
24
+ system=system if system else None,
25
+ ):
26
+ response += chunk
27
+ yield response
28
+ received_anything = True
29
+ if not received_anything:
30
+ gr.Warning("Error: Invalid API Key")
31
+ yield ""
32
+
33
+ css = """
34
+ .header-text p {line-height: 80px !important; text-align: left; font-size: 26px;}
35
+ .header-logo {text-align: left}
36
+ """
37
+
38
+ with gr.Blocks(title="Mistral Playground") as mistral_playground:
39
+ with gr.Row():
40
+ api_key = gr.Textbox(lines=1, label="Mistral API Key")
41
+ model = gr.Radio(
42
+ choices=["mistral-tiny", "mistral-small", "mistral-medium"],
43
+ value="mistral-tiny",
44
+ )
45
+ with gr.Row():
46
+ temperature = gr.Slider(minimum=0.01, maximum=1.0, value=0.2, step=0.1, label="Temperature")
47
+ top_p = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, label="Top P")
48
+ max_tokens = gr.Slider(minimum=1, maximum=16000, step=500, label="Max Tokens", value=4000)
49
+
50
+ with gr.Row():
51
+ system = gr.Textbox(lines=10, label="System Message")
52
+ gr.ChatInterface(
53
+ respond_stream,
54
+ additional_inputs=[
55
+ api_key,
56
+ model,
57
+ temperature,
58
+ top_p,
59
+ max_tokens,
60
+ system,
61
+ ],
62
+ )
63
+
64
+ mistral_playground.launch()