Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,13 +79,33 @@ def chat(message: str, conversation_history: ConversationHistory) -> Generator[T
|
|
79 |
# Yield formatted history and updated conversation history
|
80 |
yield conversation_history.get_formatted_history(), conversation_history
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
chatbot = gr.Chatbot(label="Chat")
|
83 |
conversation_history = ConversationHistory() # Initialize conversation history
|
84 |
|
85 |
iface = gr.Interface(
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
)
|
|
|
91 |
iface.queue().launch()
|
|
|
79 |
# Yield formatted history and updated conversation history
|
80 |
yield conversation_history.get_formatted_history(), conversation_history
|
81 |
|
82 |
+
# Create a custom Gradio component to display the conversation history
|
83 |
+
class ConversationHistoryComponent(gr.Component):
|
84 |
+
def __init__(self, **kwargs):
|
85 |
+
super().__init__(**kwargs)
|
86 |
+
self.history = []
|
87 |
+
|
88 |
+
def build(self):
|
89 |
+
return gr.HTML(value="<div id='conversation-history'></div>")
|
90 |
+
|
91 |
+
def update(self, history: List[Tuple[str, str]]):
|
92 |
+
history_html = "<ul>"
|
93 |
+
for user_message, assistant_message in history:
|
94 |
+
history_html += f"<li><strong>User:</strong> {user_message}</li>"
|
95 |
+
if assistant_message is not None:
|
96 |
+
history_html += f"<li><strong>Assistant:</strong> {assistant_message}</li>"
|
97 |
+
history_html += "</ul>"
|
98 |
+
self.history = history
|
99 |
+
return gr.HTML(value=history_html)
|
100 |
+
|
101 |
chatbot = gr.Chatbot(label="Chat")
|
102 |
conversation_history = ConversationHistory() # Initialize conversation history
|
103 |
|
104 |
iface = gr.Interface(
|
105 |
+
fn=chat,
|
106 |
+
inputs=[gr.Textbox(placeholder="Hello! How are you?", label="Message")],
|
107 |
+
outputs=[chatbot, ConversationHistoryComponent(label="Conversation History")],
|
108 |
+
allow_flagging="never",
|
109 |
)
|
110 |
+
|
111 |
iface.queue().launch()
|