File size: 2,264 Bytes
271f307
 
 
 
0064343
 
 
 
271f307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9241ac6
271f307
 
 
 
 
 
 
 
 
 
 
 
 
2197af3
8052ea6
 
 
 
 
2197af3
271f307
0064343
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from huggingface_hub import InferenceClient
import gradio as gr
import random
import prompts
from pypipertts import PyPiper
pp=PyPiper()
pp.load_mod(instr="en_US-joe-medium")

client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")

def format_prompt(message, history):

  prompt = "<s>"
  for user_prompt, bot_response in history:
    print (bot_response)
    prompt += f"[INST] {user_prompt} [/INST]"
    prompt += f" {bot_response}</s> "
  prompt += f"[INST] {message} [/INST]"
  return prompt

def generate(prompt,history,max_new_tokens,seed):
    #seed = random.randint(1,9999999999999)
    print(seed)
    system_prompt = prompts.AI_REPORT_WRITER
    generate_kwargs = dict(
        temperature=0.9,
        max_new_tokens=max_new_tokens,
        top_p=0.95,
        repetition_penalty=1.0,
        do_sample=True,
        seed=seed,
    )

    formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
    stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
    output = ""

    for response in stream:
        if response.token.text == "\n":
            yield from pp.stream_tts(output)
            output=""
        output += response.token.text
        
        #yield output

with gr.Blocks() as iface:
    gr.HTML("""""")
    aud=gr.Audio(streaming=True,autoplay=True)
    #chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
    chatbot=gr.Chatbot()
    msg = gr.Textbox()
    with gr.Row():
        submit_b = gr.Button()
        stop_b = gr.Button("Stop")
        clear = gr.ClearButton([msg, chatbot])
    sumbox=gr.Textbox("Summary", max_lines=100)
    with gr.Column():
        sum_out_box=gr.JSON(label="Summaries")
        hist_out_box=gr.JSON(label="History")
        
    #sub_b = submit_b.click(generate, [msg,chatbot],[msg,chatbot,sumbox,sum_out_box,hist_out_box])
    #sub_e = msg.submit(generate, [msg, chatbot], [msg, chatbot,sumbox,sum_out_box,hist_out_box])    
    sub_b = submit_b.click(generate, [msg,chatbot],aud)
    sub_e = msg.submit(generate, [msg, chatbot], aud)
    stop_b.click(None,None,None, cancels=[sub_b,sub_e])
iface.queue(default_concurrency_limit=10).launch()