File size: 694 Bytes
62ce3e8 998f824 62ce3e8 998f824 62ce3e8 8ca9de9 f5cce2a 62ce3e8 a0ecec2 998f824 62ce3e8 998f824 62ce3e8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import os
import gradio as gr
model_name = "scb10x/llama-3-typhoon-v1.5x-70b-instruct-awq"
token = os.getenv("HF_TOKEN")
# Remove these lines
# device = torch.device("cuda")
# torch.cuda.set_device(0)
tokenizer = AutoTokenizer.from_pretrained(model_name, token=token)
model = AutoModelForCausalLM.from_pretrained(model_name, token=token)
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(inputs.input_ids, max_length=50)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
gr.Interface(fn=generate_text, inputs="text", outputs="text").launch() |