marcofrodl's picture
Create app.py
2cc7027
raw
history blame
1.79 kB
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()