Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import random
|
| 3 |
import logging
|
| 4 |
from twitchio.ext import commands
|
| 5 |
-
from transformers import AutoTokenizer,
|
| 6 |
import torch
|
| 7 |
|
| 8 |
# Set up logging
|
|
@@ -29,41 +29,118 @@ missing_vars = [var for var in required_vars if not globals().get(var)]
|
|
| 29 |
if missing_vars:
|
| 30 |
raise ValueError(f"Missing environment variables: {', '.join(missing_vars)}")
|
| 31 |
|
| 32 |
-
#
|
| 33 |
model_name = "jacksonstrut/tinyllama-1.1B-chat"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
os.environ["TOKENIZERS_PARALLELISM"] = "false"
|
| 37 |
-
|
| 38 |
-
# Load the tokenizer with use_fast=False
|
| 39 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 40 |
-
model_name,
|
| 41 |
-
token=HUGGINGFACE_API_TOKEN,
|
| 42 |
-
use_fast=False
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
# Ensure pad_token is set
|
| 46 |
-
if tokenizer.pad_token is None:
|
| 47 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 48 |
-
|
| 49 |
-
config = AutoConfig.from_pretrained(model_name)
|
| 50 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 51 |
-
model_name,
|
| 52 |
-
config=config,
|
| 53 |
-
token=HUGGINGFACE_API_TOKEN
|
| 54 |
-
)
|
| 55 |
model.to('cpu')
|
| 56 |
|
| 57 |
# List of house music hooks to drop randomly
|
| 58 |
HOUSE_MUSIC_HOOKS = [
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
]
|
| 61 |
|
| 62 |
# Initialize chat history for users
|
| 63 |
chat_histories = {}
|
| 64 |
|
| 65 |
async def generate_response(user_id, user_message):
|
| 66 |
-
"""Generates a response using the model."""
|
| 67 |
try:
|
| 68 |
# Retrieve or initialize the chat history for the user
|
| 69 |
if user_id in chat_histories:
|
|
@@ -88,7 +165,7 @@ async def generate_response(user_id, user_message):
|
|
| 88 |
do_sample=True,
|
| 89 |
top_p=0.95,
|
| 90 |
top_k=50,
|
| 91 |
-
pad_token_id=tokenizer.
|
| 92 |
no_repeat_ngram_size=3,
|
| 93 |
)
|
| 94 |
|
|
@@ -143,4 +220,4 @@ class TwitchChatBot(commands.Bot):
|
|
| 143 |
# Initialize and run the bot
|
| 144 |
if __name__ == "__main__":
|
| 145 |
bot = TwitchChatBot()
|
| 146 |
-
bot.run()
|
|
|
|
| 2 |
import random
|
| 3 |
import logging
|
| 4 |
from twitchio.ext import commands
|
| 5 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 6 |
import torch
|
| 7 |
|
| 8 |
# Set up logging
|
|
|
|
| 29 |
if missing_vars:
|
| 30 |
raise ValueError(f"Missing environment variables: {', '.join(missing_vars)}")
|
| 31 |
|
| 32 |
+
# Initialize the Hugging Face tokenizer and model for DialoGPT
|
| 33 |
model_name = "jacksonstrut/tinyllama-1.1B-chat"
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, token=HUGGINGFACE_API_TOKEN)
|
| 35 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, token=HUGGINGFACE_API_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
model.to('cpu')
|
| 37 |
|
| 38 |
# List of house music hooks to drop randomly
|
| 39 |
HOUSE_MUSIC_HOOKS = [
|
| 40 |
+
"Feeling the vibe, let's get hyped!",
|
| 41 |
+
"Rave or die!",
|
| 42 |
+
"Rave to the g,rave!",
|
| 43 |
+
"He just strutts!",
|
| 44 |
+
"Dancing is what to do!",
|
| 45 |
+
"Let's get riggity riggity wrecked!",
|
| 46 |
+
"Sleep is for the week, not the weekend!",
|
| 47 |
+
"It's hard out here for a pimp!",
|
| 48 |
+
"Something for your mind!",
|
| 49 |
+
"Something for your body!",
|
| 50 |
+
"Something for your soul!",
|
| 51 |
+
"Not everyone understands this thing they call house music!",
|
| 52 |
+
"It's a spiritual thing!",
|
| 53 |
+
"Talkin' about that thing they call house music!",
|
| 54 |
+
"Don't mean a thing if it ain't got that swing!",
|
| 55 |
+
"Can't stop. Won't stop!",
|
| 56 |
+
"Shots! Shots! Shots!",
|
| 57 |
+
"Jack to the sound of the underground!",
|
| 58 |
+
"Jack your body!",
|
| 59 |
+
"Asking ya..to BELIEVE..in the MIX!",
|
| 60 |
+
"BeaverBankHouseMafia in the house baby!",
|
| 61 |
+
"Dancing all night long, can't stop the beat!",
|
| 62 |
+
"Got my hands up high, feeling alive!",
|
| 63 |
+
"The music's got me moving, can't resist the groove!",
|
| 64 |
+
"Let's ride this wave, we're on top of the world!",
|
| 65 |
+
"Feeling the energy, let it consume us all!",
|
| 66 |
+
"We're in the zone, lost in the music!",
|
| 67 |
+
"This beat is fire, can't stop dancing!",
|
| 68 |
+
"The rhythm is pumping, let's keep it real!",
|
| 69 |
+
"Get ready to party, we're on a roll!",
|
| 70 |
+
"Let's make some noise, and show them how it's done!",
|
| 71 |
+
"We're living for the moment, feeling alive tonight!",
|
| 72 |
+
"The music's got us hyped, let's keep it real!",
|
| 73 |
+
"We're in the house, and we're here to stay!",
|
| 74 |
+
"Let's rock this place, and make it feel like home!",
|
| 75 |
+
"Got my hands up high, feeling alive tonight!",
|
| 76 |
+
"The beat is strong, and so are we!",
|
| 77 |
+
"We're on the dance floor, living our best lives!",
|
| 78 |
+
"Let's keep the energy high, and the vibes bright!",
|
| 79 |
+
"Feeling the music deep inside my soul!",
|
| 80 |
+
"We're on a roll, can't stop feeling alive!",
|
| 81 |
+
"The music's got us moving, let's keep on dancing!",
|
| 82 |
+
"Feeling the magic, in every single note!",
|
| 83 |
+
"We're lost in the rhythm, and we can't be stopped!",
|
| 84 |
+
"The music's got us swaying, back and forth!",
|
| 85 |
+
"Let's keep dancing all night long!",
|
| 86 |
+
"Feeling the heat, let it consume me whole!",
|
| 87 |
+
"We're in the zone, can't stop grooving!",
|
| 88 |
+
"The music's got us high, and we won't come down!",
|
| 89 |
+
"Let's keep on moving, until the morning light!",
|
| 90 |
+
"We're in this together, let's make it feel right!",
|
| 91 |
+
"The rhythm is strong, and we can't be stopped!",
|
| 92 |
+
"Feeling the beat, deep inside my soul!",
|
| 93 |
+
"Got my heart racing, and my feet are on fire!",
|
| 94 |
+
"The music's got us moving, let's keep it real!",
|
| 95 |
+
"Feeling the energy, and we won't stop until the break of dawn!",
|
| 96 |
+
"Got my hands up high, feeling alive tonight!",
|
| 97 |
+
"The beat is strong, and so are we!",
|
| 98 |
+
"Got my feet tapping, and my heart is pounding!",
|
| 99 |
+
"Feeling the magic, in every single note!",
|
| 100 |
+
"Let's keep on dancing all night long, feeling alive tonight!",
|
| 101 |
+
"We're lost in the rhythm, and can't be stopped!",
|
| 102 |
+
"Feeling the energy, let it consume me whole!",
|
| 103 |
+
"Got my heart racing, and my feet are on fire!",
|
| 104 |
+
"The music's got us moving, can't stop dancing!",
|
| 105 |
+
"Feeling the beat, deep inside my soul!",
|
| 106 |
+
"Let's keep on dancing, until we reach our goal!",
|
| 107 |
+
"We're on a roll, can't stop living our best lives!",
|
| 108 |
+
"The music's got us moving, can't stop swaying!",
|
| 109 |
+
"Feeling the energy, let it consume me whole!",
|
| 110 |
+
"We're in this together, let's make it feel right!",
|
| 111 |
+
"Got my heart racing, and my feet are on fire!",
|
| 112 |
+
"Feeling the magic, in every single note!",
|
| 113 |
+
"We're lost in the rhythm, and can't be stopped!",
|
| 114 |
+
"The music's got us swaying, back and forth!",
|
| 115 |
+
"Feeling the heat, let it consume me whole!",
|
| 116 |
+
"The beat is strong, and so are we!",
|
| 117 |
+
"Got my feet tapping, and my heart is pounding!",
|
| 118 |
+
"Let's keep dancing all night long, feeling alive tonight!",
|
| 119 |
+
"Feeling the energy, let it take control!",
|
| 120 |
+
"We're lost in the music, can't be found!",
|
| 121 |
+
"Got my hands up high, feeling alive tonight!",
|
| 122 |
+
"Feeling the vibe, let's keep it real!",
|
| 123 |
+
"We're on a roll, can't stop living our best lives!",
|
| 124 |
+
"Got my heart racing, and my feet are on fire!",
|
| 125 |
+
"The music's got us moving, can't stop grooving!",
|
| 126 |
+
"Feeling the magic, in every single note!",
|
| 127 |
+
"We're lost in the rhythm, and can't be stopped!",
|
| 128 |
+
"Got my feet tapping, and my heart is pounding!",
|
| 129 |
+
"Feeling the energy, let it take control!",
|
| 130 |
+
"We're on a roll, can't stop living our best lives!",
|
| 131 |
+
"The beat is strong, and so are we!",
|
| 132 |
+
"Feeling the energy, let it consume me whole!",
|
| 133 |
+
"Got my feet tapping, and my heart is pounding!",
|
| 134 |
+
"Feeling the beat, deep inside my soul!",
|
| 135 |
+
"Got my heart racing, and my feet are on fire!",
|
| 136 |
+
"The music's got us moving, can't stop dancing!",
|
| 137 |
]
|
| 138 |
|
| 139 |
# Initialize chat history for users
|
| 140 |
chat_histories = {}
|
| 141 |
|
| 142 |
async def generate_response(user_id, user_message):
|
| 143 |
+
"""Generates a response using the DialoGPT model."""
|
| 144 |
try:
|
| 145 |
# Retrieve or initialize the chat history for the user
|
| 146 |
if user_id in chat_histories:
|
|
|
|
| 165 |
do_sample=True,
|
| 166 |
top_p=0.95,
|
| 167 |
top_k=50,
|
| 168 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 169 |
no_repeat_ngram_size=3,
|
| 170 |
)
|
| 171 |
|
|
|
|
| 220 |
# Initialize and run the bot
|
| 221 |
if __name__ == "__main__":
|
| 222 |
bot = TwitchChatBot()
|
| 223 |
+
bot.run()
|