hertogateis commited on
Commit
61e5bf4
·
verified ·
1 Parent(s): 9e8385f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -15
app.py CHANGED
@@ -1,22 +1,52 @@
 
1
  import requests
2
 
 
 
 
 
3
  url = "https://api.hyperbolic.xyz/v1/chat/completions"
4
  headers = {
5
  "Content-Type": "application/json",
6
  "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"
7
  }
8
- data = {
9
- "messages": [
10
- {
11
- "role": "user",
12
- "content": "What can I do in SF?"
13
- }
14
- ],
15
- "model": "deepseek-ai/DeepSeek-V3",
16
- "max_tokens": 512,
17
- "temperature": 0.1,
18
- "top_p": 0.9
19
- }
20
-
21
- response = requests.post(url, headers=headers, json=data)
22
- print(response.json())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import requests
3
 
4
+ # Set up Streamlit page configuration
5
+ st.set_page_config(page_title="DeepSeek Chatbot", page_icon="🤖", layout="wide")
6
+
7
+ # API setup
8
  url = "https://api.hyperbolic.xyz/v1/chat/completions"
9
  headers = {
10
  "Content-Type": "application/json",
11
  "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"
12
  }
13
+
14
+ # Chat history container
15
+ if 'messages' not in st.session_state:
16
+ st.session_state.messages = []
17
+
18
+ # Function to send message and get response
19
+ def get_response(user_input):
20
+ data = {
21
+ "messages": [{"role": "user", "content": user_input}],
22
+ "model": "deepseek-ai/DeepSeek-V3",
23
+ "max_tokens": 512,
24
+ "temperature": 0.1,
25
+ "top_p": 0.9
26
+ }
27
+
28
+ response = requests.post(url, headers=headers, json=data)
29
+ return response.json()
30
+
31
+ # Streamlit chat UI
32
+ st.title("DeepSeek AI Chatbot")
33
+
34
+ # Display the chat history
35
+ for message in st.session_state.messages:
36
+ if message["role"] == "user":
37
+ st.chat_message("user").markdown(message["content"])
38
+ else:
39
+ st.chat_message("assistant").markdown(message["content"])
40
+
41
+ # Accept user input
42
+ user_input = st.text_input("You: ", "")
43
+
44
+ # Handle user input and update the chat
45
+ if user_input:
46
+ st.session_state.messages.append({"role": "user", "content": user_input})
47
+ response = get_response(user_input)
48
+
49
+ # Assuming the response is in the 'choices' field of the API response
50
+ bot_response = response.get('choices', [{}])[0].get('message', {}).get('content', 'Sorry, I did not understand that.')
51
+ st.session_state.messages.append({"role": "assistant", "content": bot_response})
52
+ st.experimental_rerun()