TANVEERMAKHDOOM commited on
Commit
b38fe5a
·
verified ·
1 Parent(s): 68868ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title
5
+ st.title("🤖 AI Chatbot - Hugging Face")
6
+
7
+ # Initialize chatbot model
8
+ @st.cache_resource
9
+ def load_chatbot():
10
+ return pipeline("text-generation", model="microsoft/DialoGPT-medium")
11
+
12
+ chatbot = load_chatbot()
13
+
14
+ # User input
15
+ user_input = st.text_input("You:", "")
16
+
17
+ # If user types something
18
+ if user_input:
19
+ # Generate response
20
+ with st.spinner("Chatbot is thinking..."):
21
+ response = chatbot(user_input, max_length=100, do_sample=True, pad_token_id=50256)
22
+ bot_reply = response[0]['generated_text'].split(user_input)[-1].strip()
23
+ st.markdown(f"**Bot:** {bot_reply}")