Spaces:
Runtime error
Runtime error
File size: 663 Bytes
ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 ff675a5 8830895 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import gradio as gr
from transformers import pipeline
import torch
MODEL_NAME = "ibm-granite/granite-3.3-2b-instruct"
print("Loading model...")
pipe = pipeline(
"text-generation",
model=MODEL_NAME,
device_map="auto",
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
)
print("Model loaded!")
def predict(message, history):
try:
outputs = pipe(
message,
max_new_tokens=128
)
return outputs[0]["generated_text"]
except Exception as e:
return f"Error: {str(e)}"
demo = gr.ChatInterface(
fn=predict,
title="IBM Granite Chatbot"
)
demo.launch() |