TeoJSSS commited on
Commit
509fe29
1 Parent(s): f6813b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
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 with `trust_remote_code=True`
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
- # Launch the interface
 
 
 
 
 
 
 
 
 
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)