lee-ite commited on
Commit
556ef51
·
1 Parent(s): 8060008
pages/2_Chatbot.py DELETED
@@ -1,46 +0,0 @@
1
- from openai import OpenAI
2
- import streamlit as st
3
-
4
- with st.sidebar:
5
- IFC_API_KEY = st.text_input("HF access token", key="chat_bot_api_key", type="password")
6
- selected_model = st.selectbox(
7
- "Choose a model to chat with",
8
- ("meta-llama/Llama-3.3-70B-Instruct", "meta-llama/Llama-3.1-8B-Instruct", "Qwen/QwQ-32B-Preview", "Qwen/Qwen2.5-72B-Instruct", "microsoft/Phi-3.5-mini-instruct"),
9
- )
10
- temperature = st.slider("Temperature", 0.01, 0.99, 0.5)
11
- top_p = st.slider("Top_p", 0.01, 0.99, 0.7)
12
- max_tokens = st.slider("Max Tokens", 64, 131072, 2048)
13
-
14
- st.title("💬 Chatbot")
15
- st.caption(" A HF chatbot powered by HF")
16
- if "messages" not in st.session_state:
17
- st.session_state.messages = []
18
-
19
- for msg in st.session_state.messages:
20
- with st.chat_message(msg["role"]):
21
- st.markdown(msg["content"])
22
-
23
- if prompt := st.chat_input():
24
- if not IFC_API_KEY:
25
- st.info("Please add your access token to continue.")
26
- st.stop()
27
-
28
- client = OpenAI(api_key=IFC_API_KEY, base_url="https://api-inference.huggingface.co/v1/")
29
- st.session_state.messages.append({"role": "user", "content": prompt})
30
- with st.chat_message("user"):
31
- st.markdown(prompt)
32
-
33
- with st.chat_message("assistant"):
34
- stream = client.chat.completions.create(
35
- model = selected_model,
36
- messages=[
37
- {"role": m["role"], "content": m["content"]}
38
- for m in st.session_state.messages
39
- ],
40
- temperature = temperature,
41
- top_p = top_p,
42
- max_tokens = max_tokens,
43
- stream = True,
44
- )
45
- response = st.write_stream(stream)
46
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/{3_DataGen.py → 2_DataGen.py} RENAMED
File without changes
pages/{4_Compare.py → 3_Compare.py} RENAMED
File without changes