Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
from vllm import LLM, SamplingParams
|
4 |
|
5 |
-
# Load the model and tokenizer from Hugging Face
|
6 |
model_name = "facebook/opt-125m"
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
# Initialize vLLM with CPU-only configuration
|
10 |
-
vllm_model = LLM(model=model_name, tensor_parallel_size=1, device="cpu")
|
11 |
|
12 |
def generate_response(prompt, max_tokens, temperature, top_p):
|
13 |
# Tokenize the prompt
|
@@ -20,8 +20,11 @@ def generate_response(prompt, max_tokens, temperature, top_p):
|
|
20 |
top_p=top_p,
|
21 |
)
|
22 |
|
23 |
-
# Generate text using vLLM
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
# Decode the generated tokens to text
|
27 |
generated_text = tokenizer.decode(output[0]["token_ids"], skip_special_tokens=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer
|
3 |
from vllm import LLM, SamplingParams
|
4 |
|
5 |
+
# Load the model and tokenizer from Hugging Face
|
6 |
model_name = "facebook/opt-125m"
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
# Initialize vLLM with CPU-only configuration
|
10 |
+
vllm_model = LLM(model=model_name, tensor_parallel_size=1, device="cpu", async_output=False)
|
11 |
|
12 |
def generate_response(prompt, max_tokens, temperature, top_p):
|
13 |
# Tokenize the prompt
|
|
|
20 |
top_p=top_p,
|
21 |
)
|
22 |
|
23 |
+
# Generate text using vLLM (synchronous mode)
|
24 |
+
try:
|
25 |
+
output = vllm_model.generate(inputs["input_ids"], sampling_params)
|
26 |
+
except NotImplementedError as e:
|
27 |
+
return f"Error: {e}. Ensure that async_output is supported or disabled."
|
28 |
|
29 |
# Decode the generated tokens to text
|
30 |
generated_text = tokenizer.decode(output[0]["token_ids"], skip_special_tokens=True)
|