sabahat-shakeel commited on
Commit
a61e06e
·
verified ·
1 Parent(s): 8f7bde3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
app.py CHANGED
@@ -45,15 +45,14 @@ from transformers import pipeline
45
  # Configure the Hugging Face API key
46
  HUGGINGFACE_API_KEY = st.secrets['huggingface_api_key']
47
 
48
- # Initialize the Hugging Face conversational model
49
- # You can replace 'microsoft/DialoGPT-medium' with any other supported conversational model
50
- chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
51
 
52
  # Function to get response from the Hugging Face model
53
  def get_chatbot_response(user_input):
54
  try:
55
- conversation = chatbot(user_input)
56
- return conversation[0]['generated_text'] # Extract the generated response
57
  except Exception as e:
58
  return f"Error: {str(e)}"
59
 
@@ -125,4 +124,3 @@ if st.session_state["history"]:
125
  st.markdown(f'<div class="chat-bubble user-bubble"><span class="emoji">👤</span>You: {user_input}</div>', unsafe_allow_html=True)
126
  st.markdown(f'<div class="chat-bubble bot-bubble"><span class="emoji">🤖</span>Bot: {response}</div>', unsafe_allow_html=True)
127
  st.markdown('</div>', unsafe_allow_html=True)
128
-
 
45
  # Configure the Hugging Face API key
46
  HUGGINGFACE_API_KEY = st.secrets['huggingface_api_key']
47
 
48
+ # Initialize the Hugging Face text-generation model (DialoGPT or other conversational models)
49
+ chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium", api_key=HUGGINGFACE_API_KEY)
 
50
 
51
  # Function to get response from the Hugging Face model
52
  def get_chatbot_response(user_input):
53
  try:
54
+ response = chatbot(user_input, max_length=1000, pad_token_id=50256) # Generate response
55
+ return response[0]['generated_text'] # Extract the generated response
56
  except Exception as e:
57
  return f"Error: {str(e)}"
58
 
 
124
  st.markdown(f'<div class="chat-bubble user-bubble"><span class="emoji">👤</span>You: {user_input}</div>', unsafe_allow_html=True)
125
  st.markdown(f'<div class="chat-bubble bot-bubble"><span class="emoji">🤖</span>Bot: {response}</div>', unsafe_allow_html=True)
126
  st.markdown('</div>', unsafe_allow_html=True)