Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
4 |
+
|
5 |
+
def chat_inf(system_prompt,prompt,history):
|
6 |
+
if not history:
|
7 |
+
history = []
|
8 |
+
hist_len=0
|
9 |
+
if history:
|
10 |
+
hist_len=len(history)
|
11 |
+
print(hist_len)
|
12 |
+
seed = random.randint(1,1111111111111111)
|
13 |
+
generate_kwargs = dict(
|
14 |
+
temperature=0.9,
|
15 |
+
max_new_tokens=10480,
|
16 |
+
top_p=0.95,
|
17 |
+
repetition_penalty=1.0,
|
18 |
+
do_sample=True,
|
19 |
+
seed=seed,
|
20 |
+
)
|
21 |
+
|
22 |
+
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
23 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
24 |
+
output = ""
|
25 |
+
|
26 |
+
for response in stream:
|
27 |
+
output += response.token.text
|
28 |
+
yield [(prompt,output)]
|
29 |
+
history.append((prompt,output))
|
30 |
+
yield history
|
31 |
+
|
32 |
+
with gr.Blocks() as app:
|
33 |
+
with gr.Group():
|
34 |
+
chat_b = gr.Chatbot()
|
35 |
+
with gr.Row():
|
36 |
+
with gr.Column(scale=3):
|
37 |
+
inp = gr.Textbox(label="Prompt")
|
38 |
+
sys_inp = gr.Textbox(label="System Prompt (optional)")
|
39 |
+
btn = gr.Button("Chat")
|
40 |
+
|
41 |
+
with gr.Column(scale=1):
|
42 |
+
with gr.Group():
|
43 |
+
stop_btn=gr.Button("Stop")
|
44 |
+
clear_btn=gr.Button("Clear")
|
45 |
+
chatblock=gr.Dropdown(label="Chatblocks",choices=[c for c in range(1,40)],multiselect=True)
|
46 |
+
btn.click(chat_inf,[sys_inp,inp,chat_b],chat_b)
|
47 |
+
app.launch()
|