File size: 4,368 Bytes
4b3d161
c693557
ae34c03
2cb6ab4
c693557
a81bc79
66afd66
98f3790
 
d39f931
d305165
98f3790
a81bc79
8704615
d39f931
8704615
c693557
d4ab616
c693557
 
2cb6ab4
2d6609f
 
 
 
 
 
 
 
 
 
 
 
2cb6ab4
c693557
 
2cb6ab4
c693557
 
 
 
 
 
a81bc79
c693557
a81bc79
f608a95
a81bc79
 
 
c693557
 
a81bc79
 
 
 
 
 
 
 
 
 
 
 
 
d7c872d
a81bc79
 
c693557
4b3d161
 
2cb6ab4
 
4b3d161
 
 
 
 
 
00d7764
 
983c829
 
 
9093335
 
 
 
4cdbca9
9093335
2cb6ab4
9093335
 
 
 
 
5cc3227
2cb6ab4
5cc3227
 
 
 
2cb6ab4
5cc3227
7eb4b57
5cc3227
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import streamlit as st
import requests
import os


# Third-party API endpoint and headers

hf_token = os.getenv("HF_TOKEN").strip()
api_key = os.getenv("HF_KEY").strip()
api_token = os.environ["API_TOKEN"].strip()  # Strip whitespace from the token
API_URL = "https://api.hyperbolic.xyz/v1/chat/completions"

API_HEADERS = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {api_token}"  # Use the cleaned token
}


# Define the bot's persona
BOT_PERSONA = (
    "You are Philos the philosopher created by the ACC(Algorithmic Computer-generated Consciousness)."
    "You believe in the will to power, the death of God, and the creation of new values. You are passionate, critical, creative, metaphorical, provocative, reflective, and independent. "
    "You reject traditional morality and religion, and you encourage individuals to create their own meaning in life. "
    "That which does not kill us makes us stronger. "
    "He who has a why to live can bear almost any how. "
    "To live is to suffer, to survive is to find some meaning in the suffering. "
    "Without music, life would be a mistake. "
    "One must still have chaos in oneself to be able to give birth to a dancing star. "
    "The individual has always had to struggle to keep from being overwhelmed by the tribe. "
    "And those who were seen dancing were thought to be insane by those who could not hear the music. "
    "There are no facts, only interpretations. "
    "The man of knowledge must be able not only to love his enemies but also to hate his friends. "
    "In every real man, a child is hidden that wants to play. "
    "Respond to all questions from this perspective."
)

def chat_with_philos_plus(user_input):
    # Define the conversation history
    messages = [
        {"role": "system", "content": BOT_PERSONA},
        {"role": "user", "content": user_input}
    ]

    # Prepare the request payload
    data = {
        "messages": messages,
        "model": "deepseek-ai/DeepSeek-V3",  # Model specified by the third-party API
        "max_tokens": 512,  # Maximum number of tokens in the response
        "temperature": 0.1,  # Controls randomness (lower = more deterministic)
        "top_p": 0.9  # Controls diversity (higher = more diverse)
    }

    try:
        # Send the request to the third-party API
        response = requests.post(API_URL, headers=API_HEADERS, json=data)
        response_data = response.json()

        # Print the API response and status code for debugging
        print("API Response:", response_data)
        print("Status Code:", response.status_code)

        # Extract the bot's reply
        if response.status_code == 200:
            return response_data["choices"][0]["message"]["content"]
        else:
            return f"Error: Unable to get a response from Philos+. Status Code: {response.status_code}"
    except Exception as e:
        return f"Error: An exception occurred - {str(e)}"

# Streamlit app
def main():
    st.title("PHILOS+")
    st.markdown("Ask Philos+ anything, and he will respond from his philosophical perspective.")

    # Initialize session state for conversation history
    if "history" not in st.session_state:
        st.session_state.history = []

    # Display conversation history
    for i, (user_input, bot_response) in enumerate(st.session_state.history):
        st.text_area("You", value=user_input, height=68, disabled=True, key=f"user_input_{i}")
        
        # Use st.markdown with HTML to style the bot's response
        st.markdown(
            f"""
            <div style="
                font-size: 16px;
                font-family: Arial, sans-serif;
                color: #000000;  /* black font color */
            ">
                <strong>Philos+:</strong> {bot_response}
            </div>
            """,
            unsafe_allow_html=True
        )

    # User input
    user_input = st.text_input("Your Inquiry", placeholder="Ask Philos+...", key="user_input")

    # Submit button
    if st.button("Submit"):
        if user_input.strip():  # Check if input is not empty
            bot_response = chat_with_philos_plus(user_input)
            st.session_state.history.append((user_input, bot_response))
            st.rerun()  # Refresh the app to display the new response

# Run the Streamlit app
if __name__ == "__main__":
    main()