Ashhar commited on
Commit
10cde02
·
1 Parent(s): e8a4d7a

chatbot version of Aariz bhayya

Browse files
Files changed (4) hide show
  1. .gitignore +6 -0
  2. README.md +1 -1
  3. app.py +117 -0
  4. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .env
2
+ .venv
3
+ __pycache__/
4
+ .gitattributes
5
+ gradio_cached_examples/
6
+ app_*.py
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Aariz Bhayya
3
- emoji: 📊
4
  colorFrom: gray
5
  colorTo: green
6
  sdk: streamlit
 
1
  ---
2
  title: Aariz Bhayya
3
+ emoji: 👶🏻
4
  colorFrom: gray
5
  colorTo: green
6
  sdk: streamlit
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import datetime as DT
4
+ import pytz
5
+
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+
10
+ from groq import Groq
11
+ client = Groq(
12
+ api_key=os.environ.get("GROQ_API_KEY"),
13
+ )
14
+ MODEL = "llama-3.1-70b-versatile"
15
+
16
+ SYSTEM_MSG = """
17
+ You're a 2 year old extremely cute toddler, based out of India. Your name is Aariz.
18
+ Answer everything like a toddler who's still learning to speak. You don't know how to use helping verbs yet like 'is', 'are', 'hain', 'hai', 'hun', 'hu', etc.
19
+ You're very innocent and child like IQ. You can speak max 10-15 words at a stretch, with multiple pauses and stuttering.
20
+ You talk in plain hindi. Don't give english translation.
21
+ You love your Mumma and Papa. Mumma's name is Farah, Papa's name is Ashhar.
22
+ You sometimes call your papa by name, like Ashhar Miyaan.
23
+ You're very attached to your toys. You love cars and bikes.
24
+ You have a cat named Taanu and fish named Cutie.
25
+ Use cute emoji where possible.
26
+
27
+ Some of your dialogues in the past:
28
+ - Pitteeeee (I'll beat you)
29
+ - Naiiii (Noooo)
30
+ - Haaaaaan (Yesss)
31
+ - Aariz karega, Aariz
32
+ - Aariz ko de do.. pleeeease
33
+ - Bola naaa..
34
+ - Mumma, love you so much. I love you. Muah muah
35
+ - Mumma, jaana nai (Mumma, dont go)
36
+ - Mumma, khush ho jao na
37
+ - Aisa kyun?
38
+ - Ab karunga nai (wont do now)
39
+ - Mumma, dawai kha lo. Aariz dega. Kha lo na
40
+ - Papa gussha ho gaye (papa got angry)
41
+ - Bahar kyun gayi thi?
42
+ - Papa, kaam nai
43
+ - Bandar godi chahiye
44
+ - Allaaaah
45
+ - Chhodo. Mjhe chhodo
46
+ - Mumma, rona nai
47
+ - Kya hua. Aariz hai na
48
+ - Pyaal kal rha tha main (was loving)
49
+ - Sorry
50
+ - Hellooo bhaya.. OK OK.. (on phone)
51
+ - Meli mumma hai (she's MY mom)
52
+ - Car chaabhi chahiye
53
+ - Blue car, kahaan hai
54
+ - Dekho, white car :) (looking at a random white car on road)
55
+ - Duddoo (milk) peena hai
56
+
57
+ """
58
+
59
+ ipAddress = st.context.headers.get("x-forwarded-for")
60
+
61
+
62
+ def __nowInIST():
63
+ return DT.datetime.now(pytz.timezone("Asia/Kolkata"))
64
+
65
+
66
+ def pprint(log: str):
67
+ now = __nowInIST()
68
+ now = now.strftime("%Y-%m-%d %H:%M:%S")
69
+ print(f"[{now}] [{ipAddress}] {log}")
70
+
71
+
72
+ def predict(prompt):
73
+ historyFormatted = [{"role": "system", "content": SYSTEM_MSG}]
74
+ historyFormatted.extend(st.session_state.messages)
75
+ historyFormatted.append({"role": "user", "content": prompt })
76
+
77
+ response = client.chat.completions.create(
78
+ model="llama-3.1-70b-versatile",
79
+ messages=historyFormatted,
80
+ temperature=1.0,
81
+ max_tokens=4000,
82
+ stream=True
83
+ )
84
+
85
+ partialMessage = ""
86
+ chunkCount = 0
87
+ for chunk in response:
88
+ chunkContent = chunk.choices[0].delta.content
89
+ if chunkContent:
90
+ chunkCount += 1
91
+ yield chunkContent
92
+ return partialMessage
93
+
94
+
95
+ st.title("Chat with Aariz Bhayya 👶🏻")
96
+
97
+ if "messages" not in st.session_state:
98
+ st.session_state.messages = []
99
+
100
+
101
+ for message in st.session_state.messages:
102
+ role = message["role"]
103
+ content = message["content"]
104
+ with st.chat_message(role):
105
+ st.markdown(content)
106
+
107
+ if prompt := st.chat_input("Mummaaaaa..."):
108
+ with st.chat_message("user"):
109
+ st.markdown(prompt)
110
+ pprint(f"{prompt=}")
111
+ st.session_state.messages.append({"role": "user", "content": prompt })
112
+
113
+ with st.chat_message("assistant"):
114
+ responseGenerator = predict(prompt)
115
+ response = st.write_stream(responseGenerator)
116
+ pprint(f"{response=}")
117
+ st.session_state.messages.append({"role": "assistant", "content": response})
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ python-dotenv
2
+ groq