tes3 / app.py
khaled123's picture
Create app.py
55ab7e3 verified
raw
history blame contribute delete
815 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizer
model_name = "khaled123/chess"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Define the function to generate text
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(inputs["input_ids"], max_length=50)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return generated_text
# Create the Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Chess Model based on LLaMA 2",
description="Type a prompt and the model will generate text based on it."
)
# Launch the interface
iface.launch()