Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,35 @@
|
|
1 |
-
import
|
2 |
-
import requests
|
3 |
-
import
|
4 |
-
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
if st.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
# Get token securely
|
6 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
7 |
+
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
|
9 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
10 |
+
|
11 |
+
def query(payload):
|
12 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
13 |
+
return response.json()
|
14 |
+
|
15 |
+
st.set_page_config(page_title="Mistral Chatbot", page_icon="🤖")
|
16 |
+
st.title("🚀 Mistral-7B AI Chat App")
|
17 |
+
|
18 |
+
if "history" not in st.session_state:
|
19 |
+
st.session_state.history = []
|
20 |
+
|
21 |
+
user_input = st.text_input("Ask me anything:")
|
22 |
+
|
23 |
+
if st.button("Send"):
|
24 |
+
if user_input:
|
25 |
+
output = query({"inputs": user_input})
|
26 |
+
try:
|
27 |
+
reply = output[0]["generated_text"]
|
28 |
+
except:
|
29 |
+
reply = "⚠️ Something went wrong. Please try again."
|
30 |
+
|
31 |
+
st.session_state.history.append(("You", user_input))
|
32 |
+
st.session_state.history.append(("AI", reply))
|
33 |
+
|
34 |
+
for role, text in st.session_state.history:
|
35 |
+
st.markdown(f"**{role}:** {text}")
|