LifeHelperAI commited on
Commit
3702f14
·
verified ·
1 Parent(s): 3dd6986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -1,22 +1,35 @@
1
- import streamlit as st
2
- import requests
3
- import os
4
-
5
- # Hugging Face API details
6
- API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
7
- headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"} # read from secret
8
-
9
- def query(payload):
10
- response = requests.post(API_URL, headers=headers, json=payload)
11
- return response.json()
12
-
13
- # Streamlit UI
14
- st.title("🚀 Mistral-7B AI Chat App")
15
-
16
- user_input = st.text_input("Ask me anything:")
17
-
18
- if st.button("Send"):
19
- if user_input:
20
- output = query({"inputs": user_input})
21
- st.write("### 🤖 AI Response:")
22
- st.write(output[0]["generated_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}")