Spaces:
Sleeping
Sleeping
Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from self_learning_bot import UnrestrictedChatbot
|
| 3 |
+
|
| 4 |
+
bot = UnrestrictedChatbot()
|
| 5 |
+
|
| 6 |
+
def respond(message, history):
|
| 7 |
+
response = bot.chat(message)
|
| 8 |
+
bot.save_state() # Auto-learn persistently
|
| 9 |
+
if history is None:
|
| 10 |
+
history = []
|
| 11 |
+
history.append((message, response))
|
| 12 |
+
return history, history
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("# Phoenix AI (Self-Learning Chatbot)")
|
| 16 |
+
gr.Markdown("Unrestricted, self-improving chatbot running on Hugging Face Spaces.")
|
| 17 |
+
|
| 18 |
+
chatbot = gr.Chatbot(height=480)
|
| 19 |
+
state = gr.State([])
|
| 20 |
+
|
| 21 |
+
with gr.Row():
|
| 22 |
+
txt = gr.Textbox(
|
| 23 |
+
show_label=False,
|
| 24 |
+
placeholder="Type your message here...",
|
| 25 |
+
container=False,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
txt.submit(respond, [txt, state], [chatbot, state])
|
| 29 |
+
txt.submit(lambda: "", None, txt)
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
demo.launch()
|