abdull4h commited on
Commit
36e42a7
·
verified ·
1 Parent(s): 2bbe799

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, Conversation
3
+
4
+ # Load the conversational pipeline with a local model
5
+ chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
6
+
7
+ def chat(user_input):
8
+ # Initialize a conversation with the user's message
9
+ conversation = Conversation(user_input)
10
+ # Process the conversation with the model
11
+ updated_conversation = chatbot(conversation)
12
+ # Return the most recent generated response
13
+ return updated_conversation.generated_responses[-1]
14
+
15
+ # Create the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=chat,
18
+ inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
19
+ outputs="text",
20
+ title="Local Chatbot using Transformers",
21
+ description="A simple chat application running a local model with Hugging Face Transformers."
22
+ )
23
+
24
+ if __name__ == "__main__":
25
+ iface.launch()