Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,19 +3,22 @@ from transformers import pipeline
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Open-Source Chatbot", page_icon="🤖")
|
| 5 |
|
| 6 |
-
# Load the chatbot model (
|
| 7 |
@st.cache_resource
|
| 8 |
def get_chatbot():
|
| 9 |
return pipeline(
|
| 10 |
-
"text-generation",
|
| 11 |
-
model="
|
| 12 |
device_map="auto",
|
| 13 |
-
max_new_tokens=256
|
|
|
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
chatbot = get_chatbot()
|
| 17 |
|
| 18 |
-
st.title("🤖 Open-Source Chatbot (
|
| 19 |
st.write("Ask me anything! Powered by Hugging Face's Transformers library. No API key required.")
|
| 20 |
|
| 21 |
if "chat_history" not in st.session_state:
|
|
@@ -26,10 +29,10 @@ user_input = st.text_input("You:", key="input")
|
|
| 26 |
if st.button("Send") and user_input.strip():
|
| 27 |
st.session_state.chat_history.append(("You", user_input))
|
| 28 |
with st.spinner("Thinking..."):
|
| 29 |
-
#
|
| 30 |
-
prompt =
|
| 31 |
response = chatbot(prompt)
|
| 32 |
-
bot_output = response[0]["generated_text"]
|
| 33 |
st.session_state.chat_history.append(("Bot", bot_output))
|
| 34 |
st.experimental_rerun()
|
| 35 |
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Open-Source Chatbot", page_icon="🤖")
|
| 5 |
|
| 6 |
+
# Load the chatbot model (Mistral-7B-Instruct, open model, no authentication needed)
|
| 7 |
@st.cache_resource
|
| 8 |
def get_chatbot():
|
| 9 |
return pipeline(
|
| 10 |
+
"text-generation",
|
| 11 |
+
model="mistralai/Mistral-7B-Instruct-v0.2",
|
| 12 |
device_map="auto",
|
| 13 |
+
max_new_tokens=256,
|
| 14 |
+
do_sample=True,
|
| 15 |
+
temperature=0.7,
|
| 16 |
+
top_p=0.9,
|
| 17 |
)
|
| 18 |
|
| 19 |
chatbot = get_chatbot()
|
| 20 |
|
| 21 |
+
st.title("🤖 Open-Source Chatbot (Mistral 7B Instruct)")
|
| 22 |
st.write("Ask me anything! Powered by Hugging Face's Transformers library. No API key required.")
|
| 23 |
|
| 24 |
if "chat_history" not in st.session_state:
|
|
|
|
| 29 |
if st.button("Send") and user_input.strip():
|
| 30 |
st.session_state.chat_history.append(("You", user_input))
|
| 31 |
with st.spinner("Thinking..."):
|
| 32 |
+
# Mistral (and similar) models are usually fine with a simple prompt
|
| 33 |
+
prompt = user_input
|
| 34 |
response = chatbot(prompt)
|
| 35 |
+
bot_output = response[0]["generated_text"][len(prompt):].strip() # Remove prompt from output
|
| 36 |
st.session_state.chat_history.append(("Bot", bot_output))
|
| 37 |
st.experimental_rerun()
|
| 38 |
|