Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
with gr.Blocks() as demo:
|
| 4 |
+
history = gr.State([])
|
| 5 |
+
user_question = gr.State("")
|
| 6 |
+
output_file_name = "chat_history.json"
|
| 7 |
+
|
| 8 |
+
def slow_echo(message, history):
|
| 9 |
+
for i in range(len(message)):
|
| 10 |
+
yield "You typed: " + message[: i+1]
|
| 11 |
+
|
| 12 |
+
def generate_json(history):
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
chatbox = gr.ChatInterface(
|
| 16 |
+
fn=slow_echo,
|
| 17 |
+
examples=["How can I help you?"],
|
| 18 |
+
title="Title Here",
|
| 19 |
+
description="Description for the task",
|
| 20 |
+
submit_btn="Enter",
|
| 21 |
+
stop_btn="Stop generating",
|
| 22 |
+
retry_btn="Regenerate",
|
| 23 |
+
undo_btn="Undo last message",
|
| 24 |
+
clear_btn="Start a new conversation"
|
| 25 |
+
)
|
| 26 |
+
chatbox.queue()
|
| 27 |
+
|
| 28 |
+
json_gen_btn = gr.Button("📩 Download the JSON file for your chat history!")
|
| 29 |
+
chat_history_json = []
|
| 30 |
+
json_gen_btn.click(fn=generate_json, inputs=history, outputs=chat_history_json)
|
| 31 |
+
|
| 32 |
+
demo.queue()
|
| 33 |
+
demo.launch()
|