Spaces:
Runtime error
Runtime error
File size: 838 Bytes
1cb92d8 a8fd8bb 1cb92d8 509fe29 aeac51e 1cb92d8 a8fd8bb 1cb92d8 a8fd8bb 1cb92d8 509fe29 a8fd8bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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)
|