Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,16 @@
|
|
| 1 |
"""
|
| 2 |
Simple Chatbot
|
| 3 |
-
@author: Nigel Gebodh
|
| 4 |
-
@email: [email protected]
|
| 5 |
"""
|
| 6 |
|
| 7 |
import streamlit as st
|
| 8 |
-
|
| 9 |
import os
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
|
| 14 |
# Initialize the client
|
| 15 |
-
|
| 16 |
-
base_url="https://api-inference.huggingface.co/v1",
|
| 17 |
-
api_key=os.environ.get('HUGGINGFACEHUB_API_TOKEN') # Replace with your token
|
| 18 |
-
)
|
| 19 |
|
| 20 |
model_link = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 21 |
|
|
@@ -57,18 +52,16 @@ if prompt:
|
|
| 57 |
# Display assistant response in chat message container
|
| 58 |
with st.chat_message("assistant"):
|
| 59 |
try:
|
| 60 |
-
response =
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
temperature=temperature,
|
| 67 |
-
max_tokens=3000
|
| 68 |
-
)['choices'][0]['message']['content']
|
| 69 |
|
| 70 |
-
|
| 71 |
-
st.
|
|
|
|
| 72 |
|
| 73 |
except Exception as e:
|
| 74 |
st.markdown("An error occurred. Please try again later.")
|
|
|
|
| 1 |
"""
|
| 2 |
Simple Chatbot
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import streamlit as st
|
| 6 |
+
import openai # Ensure you have the correct import
|
| 7 |
import os
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
# Initialize the client
|
| 13 |
+
openai.api_key = os.environ.get('HUGGINGFACEHUB_API_TOKEN') # Replace with your token
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
model_link = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 16 |
|
|
|
|
| 52 |
# Display assistant response in chat message container
|
| 53 |
with st.chat_message("assistant"):
|
| 54 |
try:
|
| 55 |
+
response = openai.Completion.create(
|
| 56 |
+
engine=model_link,
|
| 57 |
+
prompt=prompt,
|
| 58 |
+
max_tokens=3000,
|
| 59 |
+
temperature=temperature
|
| 60 |
+
)
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
response_content = response.choices[0].text.strip()
|
| 63 |
+
st.markdown(response_content)
|
| 64 |
+
st.session_state.messages.append({"role": "assistant", "content": response_content})
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
st.markdown("An error occurred. Please try again later.")
|