Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122import requestsurl = "https://api.hyperbolic.xyz/v1/chat/completions"headers = {"Content-Type": "application/json","Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"}data = {"messages": [{"role": "user","content": "What can I do in SF?"}],"model": "deepseek-ai/DeepSeek-V3","max_tokens": 512,"temperature": 0.1,"top_p": 0.9}response = requests.post(url, headers=headers, json=data)print(response.json())12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import streamlit as stimport requests# Set up Streamlit page configurationst.set_page_config(page_title="DeepSeek Chatbot", page_icon="🤖", layout="wide")# API setupurl = "https://api.hyperbolic.xyz/v1/chat/completions"headers = {"Content-Type": "application/json","Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtaXRyYWxlc3RhcmlwZXJzYWRhQGdtYWlsLmNvbSIsImlhdCI6MTczNjUwMzQxMX0.yuIoZsH1jouAlixx_h_eQ-bltZ1sg4alrJHMHr1axvA"}# Chat history containerif 'messages' not in st.session_state:st.session_state.messages = []# Function to send message and get responsedef get_response(user_input):data = {"messages": [{"role": "user", "content": user_input}],"model": "deepseek-ai/DeepSeek-V3","max_tokens": 512,"temperature": 0.1,"top_p": 0.9}response = requests.post(url, headers=headers, json=data)return response.json()# Streamlit chat UIst.title("DeepSeek AI Chatbot")# Display the chat historyfor message in st.session_state.messages:if message["role"] == "user":st.chat_message("user").markdown(message["content"])else:st.chat_message("assistant").markdown(message["content"])# Accept user inputuser_input = st.text_input("You: ", "")# Handle user input and update the chatif user_input:st.session_state.messages.append({"role": "user", "content": user_input})response = get_response(user_input)# Assuming the response is in the 'choices' field of the API responsebot_response = response.get('choices', [{}])[0].get('message', {}).get('content', 'Sorry, I did not understand that.')st.session_state.messages.append({"role": "assistant", "content": bot_response})st.experimental_rerun()
app.py+45-15