Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,40 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
with gr.Blocks() as demo:
|
| 4 |
-
|
| 5 |
-
user_question = gr.State("")
|
| 6 |
-
output_file_name = "chat_history.json"
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
def generate_json(
|
| 13 |
-
|
| 14 |
|
| 15 |
chatbox = gr.ChatInterface(
|
| 16 |
-
fn=
|
| 17 |
-
|
| 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 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
demo.queue()
|
| 33 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
with gr.Blocks() as demo:
|
| 4 |
+
chat_history = gr.State(value=[])
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def echo(message, history):
|
| 7 |
+
response = "You typed: " + message
|
| 8 |
+
chat_history.value.append(
|
| 9 |
+
{
|
| 10 |
+
"user": message,
|
| 11 |
+
"bot": response,
|
| 12 |
+
}
|
| 13 |
+
)
|
| 14 |
+
return response
|
| 15 |
|
| 16 |
+
def generate_json(chat_history):
|
| 17 |
+
return chat_history.value
|
| 18 |
|
| 19 |
chatbox = gr.ChatInterface(
|
| 20 |
+
fn=echo,
|
| 21 |
+
|
| 22 |
title="Title Here",
|
| 23 |
description="Description for the task",
|
| 24 |
+
examples=["How can I help you?"],
|
| 25 |
+
|
| 26 |
submit_btn="Enter",
|
| 27 |
stop_btn="Stop generating",
|
| 28 |
retry_btn="Regenerate",
|
| 29 |
undo_btn="Undo last message",
|
| 30 |
clear_btn="Start a new conversation"
|
| 31 |
+
).queue()
|
| 32 |
+
|
| 33 |
+
chat_history_json = gr.JSON(generate_json(chat_history))
|
| 34 |
+
gr.Markdown("### 📩 Generate the JSON file for your chat history!")
|
| 35 |
+
gr.Interface(fn=generate_json,
|
| 36 |
+
inputs=None,
|
| 37 |
+
outputs=[ chat_history_json ])
|
| 38 |
+
|
| 39 |
demo.queue()
|
| 40 |
demo.launch()
|