SimonGPT / app.py
Simonsbs's picture
Refactor model loading and response generation in app.py; update requirements.txt
318fc31
Raw History Blame Contribute Delete
718 Bytes
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
# Load the tokenizer and model
model_name = "HuggingFaceTB/SmolLM2-360M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Create a text-generation pipeline
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
# Define the response function
def respond(prompt):
response = generator(prompt, max_length=512, do_sample=True, temperature=0.7)
return response[0]["generated_text"]
# Create the Gradio interface
iface = gr.Interface(fn=respond, inputs="text", outputs="text", title="SimonGPT")
# Launch the app
iface.launch()