Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a conversational model
|
| 5 |
+
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
| 6 |
+
|
| 7 |
+
def chat_with_bot(user_input, history=[]):
|
| 8 |
+
from transformers import ConversationalPipeline, Conversation
|
| 9 |
+
conversation = Conversation(user_input)
|
| 10 |
+
convo = chatbot(conversation)
|
| 11 |
+
response = convo.generated_responses[-1]
|
| 12 |
+
history.append((user_input, response))
|
| 13 |
+
return response, history
|
| 14 |
+
|
| 15 |
+
demo = gr.Interface(
|
| 16 |
+
fn=chat_with_bot,
|
| 17 |
+
inputs=[
|
| 18 |
+
gr.Textbox(lines=2, placeholder="Say something..."),
|
| 19 |
+
gr.State()
|
| 20 |
+
],
|
| 21 |
+
outputs=[
|
| 22 |
+
gr.Textbox(lines=6, label="🤖 Bot says"),
|
| 23 |
+
gr.State()
|
| 24 |
+
],
|
| 25 |
+
title="💬 Everyday Chatbot",
|
| 26 |
+
description="Talk to your AI buddy about anything — life, school, ideas, or just random stuff!"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|