import gradio as gr from transformers import AutoModelForCausalLM, AutoTokenizer # Load the model and tokenizer tokenizer = AutoTokenizer.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True) def generate_response(prompt): inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs) return tokenizer.decode(outputs[0], skip_special_tokens=True) iface = gr.Interface(fn=generate_response, inputs="text", outputs="text") # Add a custom API route def api_handler(data): prompt = data['prompt'] response = generate_response(prompt) return {"response": response} iface.api_routes = { "/generate": {"POST": api_handler} } iface.launch(share=True, inline=True)