2023-07-24 23:55:47 +08:00
|
|
|
import gradio as gr
|
|
|
|
import time
|
|
|
|
|
2024-05-13 22:35:07 +08:00
|
|
|
|
2023-07-24 23:55:47 +08:00
|
|
|
def echo(message, history, system_prompt, tokens):
|
|
|
|
response = f"System prompt: {system_prompt}\n Message: {message}."
|
|
|
|
for i in range(min(len(response), int(tokens))):
|
|
|
|
time.sleep(0.05)
|
2024-05-13 22:35:07 +08:00
|
|
|
yield response[: i + 1]
|
|
|
|
|
2023-07-24 23:55:47 +08:00
|
|
|
|
2024-05-13 22:35:07 +08:00
|
|
|
demo = gr.ChatInterface(
|
|
|
|
echo,
|
|
|
|
additional_inputs=[
|
|
|
|
gr.Textbox("You are helpful AI.", label="System Prompt"),
|
|
|
|
gr.Slider(10, 100),
|
|
|
|
],
|
|
|
|
)
|
2023-07-24 23:55:47 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-05-13 22:35:07 +08:00
|
|
|
demo.queue().launch()
|