CallmeKaito commited on
Commit
0542101
Β·
verified Β·
1 Parent(s): 2ad9588

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import torch
4
+ import random
5
+
6
+ # Set page config
7
+ st.set_page_config(
8
+ page_title="🧠 Brainrot Chat",
9
+ page_icon="🧠"
10
+ )
11
+
12
+ # Initialize session state for chat history if it doesn't exist
13
+ if "messages" not in st.session_state:
14
+ st.session_state.messages = []
15
+
16
+ # Fun loading messages
17
+ LOADING_MESSAGES = [
18
+ "Rotting brain cells... 🧠",
19
+ "Downloading TikTok wisdom... πŸ“±",
20
+ "Absorbing internet culture... 🌐",
21
+ "Loading peak brainrot... πŸ€ͺ",
22
+ "Gathering viral knowledge... 🦠"
23
+ ]
24
+
25
+ def load_qa_pipeline():
26
+ """Load the question-answering pipeline"""
27
+ if "qa_pipeline" not in st.session_state:
28
+ with st.spinner(random.choice(LOADING_MESSAGES)):
29
+ st.session_state.qa_pipeline = pipeline(
30
+ "question-answering",
31
+ model="CallmeKaito/llama-3.1-8b-it-brainrot",
32
+ device=0 if torch.cuda.is_available() else -1
33
+ )
34
+
35
+ def get_answer(question, context):
36
+ """Get answer from the model"""
37
+ try:
38
+ result = st.session_state.qa_pipeline(
39
+ question=question,
40
+ context=context
41
+ )
42
+ return result['answer']
43
+ except Exception as e:
44
+ return f"Brain too rotted, can't compute 🀯 Error: {str(e)}"
45
+
46
+ # Main UI with themed styling
47
+ st.markdown("""
48
+ <style>
49
+ .big-font {
50
+ font-size: 40px !important;
51
+ font-weight: bold;
52
+ }
53
+ </style>
54
+ <p class="big-font">🧠 Brainrot Chat πŸ€ͺ</p>
55
+ """, unsafe_allow_html=True)
56
+
57
+ st.markdown("""
58
+ Welcome to the Brainrot Zone! This chatbot has been trained on peak TikTok content.
59
+ Prepare for some absolutely unhinged responses!
60
+
61
+ ⚠️ Remember: This is for entertainment only - don't take anything too seriously! ⚠️
62
+ """)
63
+
64
+ # Load the model
65
+ load_qa_pipeline()
66
+
67
+ # Example prompts to help users
68
+ EXAMPLE_CONTEXTS = [
69
+ "When the rizz is immaculate but she's literally so real for what fr fr no cap bussin",
70
+ "POV: You're chronically online and everything is giving main character energy",
71
+ "It's giving slay queen energy with a side of based behavior ngl",
72
+ ]
73
+
74
+ # Context input with example
75
+ context = st.text_area(
76
+ "Drop your TikTok wisdom here:",
77
+ placeholder=random.choice(EXAMPLE_CONTEXTS),
78
+ height=100
79
+ )
80
+
81
+ # Display chat history
82
+ for message in st.session_state.messages:
83
+ with st.chat_message(message["role"]):
84
+ st.write(message["content"])
85
+
86
+ # User input
87
+ if question := st.chat_input("Ask something absolutely unhinged..."):
88
+ # Display user message
89
+ with st.chat_message("user"):
90
+ st.write(question)
91
+ st.session_state.messages.append({"role": "user", "content": question})
92
+
93
+ # Generate and display assistant response
94
+ if context:
95
+ with st.chat_message("assistant"):
96
+ answer = get_answer(question, context)
97
+ st.write(f"{answer} {random.choice(['πŸ’…', '😌', 'πŸ’', 'πŸ€ͺ', '✨'])}")
98
+ st.session_state.messages.append({"role": "assistant", "content": answer})
99
+ else:
100
+ with st.chat_message("assistant"):
101
+ st.write("Bestie, I need some context to work with! Drop some TikTok wisdom above! ✨")
102
+ st.session_state.messages.append(
103
+ {"role": "assistant", "content": "Bestie, I need some context to work with! Drop some TikTok wisdom above! ✨"}
104
+ )
105
+
106
+ # Clear chat button with themed text
107
+ if st.button("Reset the Brainrot 🧠"):
108
+ st.session_state.messages = []
109
+ st.experimental_rerun()
110
+
111
+ # Footer
112
+ st.markdown("""
113
+ ---
114
+ *This chatbot is living its best life with maximum brainrot energy.
115
+ Any weird responses are just part of the aesthetic* ✨
116
+ """)