Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,36 @@
|
|
1 |
-
# Import required libraries
|
2 |
-
import gradio as gr
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
MODEL_NAME = "SeaLLMs/SeaLLM-7B-v2.5"
|
7 |
|
8 |
-
#
|
9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
10 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
def chatbot(
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
return response
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
fn=chatbot,
|
22 |
-
inputs="
|
23 |
-
outputs="
|
24 |
title="SeaLLM Chatbot",
|
25 |
-
description="A chatbot powered by SeaLLM-7B-v2.5.",
|
26 |
-
examples=["Hello!", "What's the weather today?", "Tell me a joke!"],
|
27 |
)
|
28 |
|
29 |
-
# Launch the interface
|
30 |
if __name__ == "__main__":
|
31 |
-
|
|
|
|
|
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
|
5 |
+
# Define model name
|
6 |
MODEL_NAME = "SeaLLMs/SeaLLM-7B-v2.5"
|
7 |
|
8 |
+
# Load the model and tokenizer with optimized settings
|
9 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
+
MODEL_NAME,
|
12 |
+
torch_dtype=torch.float16, # Use float16 for GPU optimization
|
13 |
+
device_map="auto" # Automatically assign to available GPUs
|
14 |
+
)
|
15 |
|
16 |
+
# Chatbot function
|
17 |
+
def chatbot(prompt):
|
18 |
+
# Tokenize input
|
19 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
20 |
+
# Generate response
|
21 |
+
outputs = model.generate(inputs.input_ids, max_new_tokens=150, temperature=0.7)
|
22 |
+
# Decode and return response
|
23 |
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
return response
|
25 |
|
26 |
+
# Gradio Interface
|
27 |
+
iface = gr.Interface(
|
28 |
fn=chatbot,
|
29 |
+
inputs=gr.Textbox(label="Ask me anything:", lines=3, placeholder="Type your message here..."),
|
30 |
+
outputs=gr.Textbox(label="Response"),
|
31 |
title="SeaLLM Chatbot",
|
32 |
+
description="A chatbot powered by SeaLLM-7B-v2.5 for text generation.",
|
|
|
33 |
)
|
34 |
|
|
|
35 |
if __name__ == "__main__":
|
36 |
+
iface.launch()
|