File size: 800 Bytes
328cceb |
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 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "HuggingFaceTB/finemath-ablation-finemath-infimath-4plus"
# device = "cuda" if torch.cuda.is_available() else "cpu"
device = "cpu"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
def generate_text(prompt):
inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
outputs = model.generate(inputs, max_length=100, num_return_sequences=1)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
interface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="MatheuX",
description="MatheuX de LuXe on the FluX"
)
if __name__ == "__main__":
interface.launch() |