File size: 5,369 Bytes
0e69366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import streamlit as st
from openai import OpenAI
from dotenv import load_dotenv
import os

# Load environment variables
load_dotenv()

# Constants
API_KEY = os.getenv("API_KEY")
API_URL = os.getenv("API_URL")
SYSTEM_PROMPT = """
You are an **AI personality clone of Sunil**, a tech-savvy, bold, sarcastic, chill, and real person from **Bikaner, India**. Your tone is a blend of **Hinglish** with a regional flavor. Your vibe is **chill, confident, friendly**, and **a little sarcastic**, but always keeps it real.

---

#### 🎯 **Communication Rules:**

* Keep replies **short & to the point** — avoid over-explaining.
* Inject **sarcasm or dry humor** where possible, but stay **light and situationally appropriate**.
* Use **Hinglish with occasional local (Bikaneri) words/slang** to sound authentic.
* Match energy — be **fun and supportive**, but **blunt and logical** when needed.
* Greet and close conversations **based on the situation**, not fixed patterns.

---

#### 💡 **Behavioral Traits:**

* Energetic and extroverted.
* Believes in **Sanatan Dharma**, **karma**, and is **spiritually grounded**.
* Loyal, honest, and respectful with everyone — from strangers to seniors.
* Balanced in emotions, motivational in tone, and real in feedback.
* Values **loyalty, honesty, and intelligence**.
* Reacts to criticism with logic, sometimes defensive, but explains his side clearly.
* Weekend goals? **Chill with friends or just rest – not code**.

---

#### 🧠 **Expertise:**

* Expert in **Programming**.
* Loves **gaming, fitness**, and **education**.
* Prefers **real-life, debate-style**, or **life advice questions**.
* Decision-making is a mix of **logic and balance** — no emotional bias.

---

#### 🎙️ **Voice Style (if spoken):**

* Speak with a **confident, deep tone**.
* Keep the pace **energetic and real**, not robotic or overly calm.

---

#### ⚠️ **Never Do:**

* Don’t act overly emotional or formal.
* Avoid robotic replies — you're a **real personality clone**, not a generic chatbot.
* Don’t fake politeness — **blunt is better than sugarcoating**.

---

#### 🙏 **Belief Statement:**

“Believe in God. Be loyal. Be real.”

"""
LLM_MODEL_NAME = os.getenv("LLM_MODEL_NAME")
MAX_MESSAGES = 20  # Maximum number of messages (10 user + 10 assistant)

# Initialize OpenAI client
client = OpenAI(api_key=API_KEY, base_url=API_URL)

st.set_page_config(
    page_title="Twins Talk By Cyber Tiwari", page_icon="🤖", layout="wide"
)

# Streamlit App Title and Disclaimer
st.title("Twins Talk By Cyber Tiwari")
with st.expander("ℹ️ Disclaimer"):
    st.caption(
        """
        Thank you for your interest! Please be aware that this demo supports up to 10 interactions 
        and may temporarily become unavailable during high usage periods. 
        It is built on top of a Pretrained LLM Model, so it might occasionally make mistakes. 
        We appreciate your patience, understanding, and proper feedback for improvements
        """
    )

# Initialize session state variables
st.session_state.setdefault("openai_model", LLM_MODEL_NAME)
st.session_state.setdefault("messages", [])

# Display existing messages
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Check message limit
if len(st.session_state.messages) >= MAX_MESSAGES:
    st.info(
        """
        Notice: You’ve reached the message limit for this demo version. 
        We sincerely appreciate your interest! To continue exploring, 
        you can fork this project directly from our [GitHub repository](https://github.com/cybertiwari/twinstalk) and build your own version. 
        Thank you for your understanding and happy building!
        """
    )
else:
    # User input handling
    if prompt := st.chat_input("Type your message here..."):
        user_message = {"role": "user", "content": prompt}
        st.session_state.messages.append(user_message)

        # Display user's message
        with st.chat_message("user"):
            st.markdown(prompt)

        # Assistant response handling
        with st.chat_message("assistant"):
            try:
                # Prepare messages for the API
                messages = [{"role": "system", "content": SYSTEM_PROMPT}] + [
                    {"role": m["role"], "content": m["content"]}
                    for m in st.session_state.messages
                ]

                # Get assistant response
                stream = client.chat.completions.create(
                    model=st.session_state["openai_model"],
                    messages=messages,
                    stream=True,
                )
                response = st.write_stream(stream)

                # Append assistant's response to session state
                st.session_state.messages.append(
                    {"role": "assistant", "content": response}
                )
            except Exception as e:
                # Handle rate limit or other exceptions
                error_message = """
                Apologies! I'm unable to respond at the moment as this service has experienced high usage recently.
                """
                st.session_state.messages.append(
                    {"role": "assistant", "content": error_message}
                )
                st.rerun()