crystal99's picture
Update app.py
b0655c4 verified
raw
history blame
785 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load your fine-tuned model and tokenizer
model_name = "crystal99/my-fine-tuned-model"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define the text generation function
def generate_text(prompt):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(inputs['input_ids'], max_length=100, num_return_sequences=1)
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return generated_text
# Set up the Gradio interface
iface = gr.Interface(fn=generate_text, inputs="text", outputs="text", title="Text Generator using Fine-Tuned Model")
# Launch the Gradio interface
iface.launch()