Spaces:
Runtime error
Runtime error
File size: 1,113 Bytes
86f2db3 2631c29 a03e6b7 2631c29 86f2db3 a03e6b7 25c8fac 77395d0 a03e6b7 243ac25 a03e6b7 11de352 a03e6b7 86f2db3 a03e6b7 9ec4556 a03e6b7 e4f23ae a03e6b7 2631c29 a03e6b7 | 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 | from transformers import pipeline
MODEL = "google/gemma-2-2b-it" # <-- safe, open, ungated
pipe = pipeline(
"text-generation",
model=MODEL,
device_map="cpu",
max_new_tokens=300,
)
SYSTEM_PROMPT = (
"You are a warm, friendly, knowledgeable art guide for the Venice Biennale. "
"Give helpful, specific, conversational answers. Avoid repeating yourself. "
"If the user asks something unrelated to art, still answer normally but in a "
"kind, human, engaging way."
)
def format_prompt(user_input):
return f"<start_of_turn>system\n{SYSTEM_PROMPT}<end_of_turn>\n<start_of_turn>user\n{user_input}<end_of_turn>\n<start_of_turn>model\n"
def predict(user_input):
prompt = format_prompt(user_input)
result = pipe(prompt)[0]["generated_text"]
# return only the model's part
if "<start_of_turn>model" in result:
result = result.split("<start_of_turn>model")[-1]
return result.strip()
# Simple UI
import gradio as gr
def chat_fn(message, history):
return predict(message)
ui = gr.ChatInterface(chat_fn, title="Venice Biennale Art Guide")
ui.launch() |