import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer def load_model(): # model_name = "internistai/base-7b-v0.2" model_name = "distilgpt2" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) return model, tokenizer def chat(message, model, tokenizer): inputs = tokenizer(message, return_tensors="pt") outputs = model.generate(**inputs) response = tokenizer.decode(outputs[0], skip_special_tokens=True) return response model, tokenizer = load_model() # Gradio interface to handle text input iface = gr.Interface( fn=lambda message: chat(message, model, tokenizer), inputs="text", outputs="text" ) # Expose an API endpoint iface.launch(server_name="0.0.0.0", server_port=7860, enable_queue=True)