Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
-
# Load the model and tokenizer
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
| 7 |
|
|
@@ -12,5 +12,14 @@ def generate_response(prompt):
|
|
| 12 |
|
| 13 |
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
| 14 |
|
| 15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
iface.launch(share=True, inline=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
| 6 |
model = AutoModelForCausalLM.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
| 7 |
|
|
|
|
| 12 |
|
| 13 |
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
| 14 |
|
| 15 |
+
# Add a custom API route
|
| 16 |
+
def api_handler(data):
|
| 17 |
+
prompt = data['prompt']
|
| 18 |
+
response = generate_response(prompt)
|
| 19 |
+
return {"response": response}
|
| 20 |
+
|
| 21 |
+
iface.api_routes = {
|
| 22 |
+
"/generate": {"POST": api_handler}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
iface.launch(share=True, inline=True)
|