AamirMalik commited on
Commit
e866cbe
·
verified ·
1 Parent(s): 1f7df92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,8 +1,14 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
 
4
- # Load the chatbot model using the "text-generation" task
5
- chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")
 
 
 
 
 
 
6
 
7
  # Streamlit app
8
  st.title("Electronics Component Chatbot")
@@ -25,7 +31,7 @@ if prompt := st.chat_input("What is your question?"):
25
  st.markdown(prompt)
26
 
27
  # Get chatbot response
28
- response = chatbot(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
29
 
30
  # Add chatbot response to chat history
31
  st.session_state.messages.append({"role": "assistant", "content": response})
 
1
  import streamlit as st
2
+ import requests
3
 
4
+ # Hugging Face Inference API endpoint
5
+ API_URL = "https://api-inference.huggingface.co/models/microsoft/DialoGPT-medium"
6
+ headers = {"Authorization": "Bearer YOUR_HUGGING_FACE_TOKEN"}
7
+
8
+ def query_chatbot(prompt):
9
+ payload = {"inputs": prompt}
10
+ response = requests.post(API_URL, headers=headers, json=payload)
11
+ return response.json()[0]['generated_text']
12
 
13
  # Streamlit app
14
  st.title("Electronics Component Chatbot")
 
31
  st.markdown(prompt)
32
 
33
  # Get chatbot response
34
+ response = query_chatbot(prompt)
35
 
36
  # Add chatbot response to chat history
37
  st.session_state.messages.append({"role": "assistant", "content": response})