Commit
·
b06c379
1
Parent(s):
6f1520e
Update app.py with working Gradio chatbot interface
Browse files
app.py
CHANGED
|
@@ -1,13 +1,17 @@
|
|
| 1 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 2 |
import torch
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Load tokenizer
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
|
|
|
|
|
|
| 7 |
model = AutoModelForCausalLM.from_pretrained("BWComedian/CSM-1B", trust_remote_code=True)
|
| 8 |
|
| 9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
model.to(device)
|
|
|
|
| 11 |
|
| 12 |
def generate_response(prompt):
|
| 13 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
|
@@ -31,4 +35,4 @@ demo = gr.Interface(
|
|
| 31 |
)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from transformers import AutoTokenizer
|
| 3 |
+
from transformers import AutoModelForCausalLM
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# Load LLaMA tokenizer (base tokenizer)
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B")
|
| 8 |
+
|
| 9 |
+
# Load your CSM-1B model (must support causal LM interface)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained("BWComedian/CSM-1B", trust_remote_code=True)
|
| 11 |
|
| 12 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
model.to(device)
|
| 14 |
+
model.eval()
|
| 15 |
|
| 16 |
def generate_response(prompt):
|
| 17 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
|
|
|
| 35 |
)
|
| 36 |
|
| 37 |
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|