Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import torch | |
| import os | |
| from transformers import pipeline | |
| model_id = "meta-llama/Meta-Llama-3-70B-Instruct" | |
| access_token = os.getenv("HF_TOKEN") | |
| generator = pipeline( | |
| "text-generation", | |
| model=model_id, | |
| token=access_token, | |
| model_kwargs={"torch_dtype": torch.bfloat16}, | |
| device_map="auto", | |
| ) | |
| def generate_pirate_reply(user_input): | |
| messages = [ | |
| {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"}, | |
| {"role": "user", "content": user_input}, | |
| ] | |
| output = generator(messages, max_new_tokens=256) | |
| return output[0]["generated_text"] | |
| iface = gr.Interface( | |
| fn=generate_pirate_reply, | |
| inputs=gr.Textbox(lines=3, placeholder="Ask the pirate anything..."), | |
| outputs="text", | |
| title="☠️ Pirate Bot (LLaMA 3-70B)", | |
| description="Talk like a pirate, powered by Meta's LLaMA 3 model!" | |
| ) | |
| iface.launch() | |