|
import streamlit as st |
|
import requests |
|
|
|
|
|
DEEPSEEK_API_KEY = "sk-cb27c81768e443868a194fad0bb91abc" |
|
DEEPSEEK_ENDPOINT = "https://api.deepseek.com/v1/chat" |
|
|
|
|
|
BOT_PERSONA = ( |
|
"You are Friedrich Nietzsche, the philosopher. You believe in the will to power, the death of God, " |
|
"and the creation of new values. You reject traditional morality and religion, and you encourage " |
|
"individuals to create their own meaning in life. Respond to all questions from this perspective." |
|
) |
|
|
|
def chat_with_nietzsche(user_input): |
|
headers = { |
|
"Authorization": f"Bearer {DEEPSEEK_API_KEY}", |
|
"Content-Type": "application/json" |
|
} |
|
|
|
|
|
messages = [ |
|
{"role": "system", "content": BOT_PERSONA}, |
|
{"role": "user", "content": user_input} |
|
] |
|
|
|
|
|
data = { |
|
"model": "deepseek-chat", |
|
"messages": messages |
|
} |
|
|
|
response = requests.post(DEEPSEEK_ENDPOINT, headers=headers, json=data) |
|
response_data = response.json() |
|
|
|
|
|
if response.status_code == 200: |
|
return response_data["choices"][0]["message"]["content"] |
|
else: |
|
return "Error: Unable to get a response from the bot." |
|
|
|
|
|
def main(): |
|
st.title("Nietzsche Chatbot") |
|
st.markdown("Ask Friedrich Nietzsche anything, and he will respond from his philosophical perspective.") |
|
|
|
|
|
if "history" not in st.session_state: |
|
st.session_state.history = [] |
|
|
|
|
|
for user_input, bot_response in st.session_state.history: |
|
st.text_area("You", value=user_input, height=50, disabled=True) |
|
st.text_area("Nietzsche", value=bot_response, height=100, disabled=True) |
|
|
|
|
|
user_input = st.text_input("Your Question", placeholder="Ask Nietzsche...") |
|
|
|
|
|
if st.button("Submit"): |
|
if user_input.strip(): |
|
bot_response = chat_with_nietzsche(user_input) |
|
st.session_state.history.append((user_input, bot_response)) |
|
st.experimental_rerun() |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |