File size: 1,179 Bytes
edac7d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7eaaffa
edac7d1
 
 
 
 
 
 
 
 
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
import gradio as gr
import time

def simulate_response(prompt, expected_output, words_per_second, history):
    delay = 1.0 / words_per_second if words_per_second > 0 else 0.01

    # Add user prompt
    history.append((prompt, ""))

    # Stream simulated response
    output = ""
    for word in expected_output.split():
        output += word + " "
        history[-1] = (prompt, output.strip())
        time.sleep(delay)
        yield history

with gr.Blocks(theme="default") as demo:
    gr.Markdown("## 🧠 Simulated Chatbot (LLM Style)", elem_id="title")

    chatbot = gr.Chatbot(show_label=False, height=800)
    generate_btn = gr.Button("Simulate Chat")
    with gr.Row():
        prompt_input = gr.Textbox(label="User Prompt", placeholder="Type your prompt here")
        response_input = gr.Textbox(label="Expected Output", placeholder="Type simulated response here")

    wps_slider = gr.Slider(minimum=1, maximum=5000, value=5, step=1,
                           label="Simulated Words per Second")

    generate_btn.click(
        simulate_response,
        inputs=[prompt_input, response_input, wps_slider, chatbot],
        outputs=chatbot
    )

demo.launch()