pranav2711 commited on
Commit
2c9ba1c
·
verified ·
1 Parent(s): e987a56

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +52 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import gradio as gr
4
+ import random
5
+
6
+ # Load model from your uploaded Hugging Face repo
7
+ model_name = "pranav2711/SlangBot"
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ model_name,
12
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
13
+ )
14
+
15
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
+ model.to(device)
17
+
18
+ # Slang word list to inject flavor
19
+ slang_words = [
20
+ "fr", "no cap", "sus", "bruh", "lit", "rizz", "cheugy", "mid", "deadass", "lowkey",
21
+ "highkey", "flex", "based", "pog", "vibe", "yeet", "ghosted", "simp", "drip", "goat",
22
+ "skrrt", "on god", "bussin", "sheesh", "bet", "gyatt", "slay", "fire", "nah fam"
23
+ ]
24
+
25
+ # Adds slang to base text
26
+ def slangify_response(text):
27
+ tokens = text.split()
28
+ return " ".join(
29
+ [random.choice(slang_words) if random.random() < 0.2 else word for word in tokens]
30
+ )
31
+
32
+ # Gradio chat function
33
+ def chat(user_input, history):
34
+ prompt = f"User: {user_input}\nAI (reply informally with internet slang):"
35
+ inputs = tokenizer(prompt, return_tensors="pt").to(device)
36
+ outputs = model.generate(**inputs, max_new_tokens=100, pad_token_id=tokenizer.eos_token_id)
37
+ decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
+ reply = decoded.split("AI (reply informally with internet slang):")[-1].strip()
39
+ return slangify_response(reply)
40
+
41
+ # Create the app object
42
+ app = gr.ChatInterface(
43
+ fn=chat,
44
+ title="🔥 SlangBot (Gemma-2B)",
45
+ description="SlangBot is powered by Google's Gemma-2B model and fine-tuned to respond with Gen-Z internet slang. Type anything and get vibey slang responses.",
46
+ examples=["yo", "what’s your vibe", "who are you", "explain rizz"],
47
+ theme="soft"
48
+ )
49
+
50
+ # Required for HF Spaces
51
+ if __name__ == "__main__":
52
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ accelerate