Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
|
|
@@ -23,6 +24,7 @@ def load_model(name):
|
|
| 23 |
cached[name] = (tok, mod)
|
| 24 |
return cached[name]
|
| 25 |
|
|
|
|
| 26 |
def chat_fn(message, history, selected_model):
|
| 27 |
tokenizer, model = load_model(selected_model)
|
| 28 |
# Build chat template (single‑turn for simplicity)
|
|
@@ -49,6 +51,7 @@ with gr.Blocks(title="Multi‑Model Chat") as demo:
|
|
| 49 |
label="Choose Model"
|
| 50 |
)
|
| 51 |
chat = gr.ChatInterface(
|
|
|
|
| 52 |
fn=lambda msg, hist: chat_fn(msg, hist, model_select.value),
|
| 53 |
additional_inputs=[model_select],
|
| 54 |
)
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
|
|
|
|
| 24 |
cached[name] = (tok, mod)
|
| 25 |
return cached[name]
|
| 26 |
|
| 27 |
+
@spaces.GPU()
|
| 28 |
def chat_fn(message, history, selected_model):
|
| 29 |
tokenizer, model = load_model(selected_model)
|
| 30 |
# Build chat template (single‑turn for simplicity)
|
|
|
|
| 51 |
label="Choose Model"
|
| 52 |
)
|
| 53 |
chat = gr.ChatInterface(
|
| 54 |
+
fn=chat_gpu,
|
| 55 |
fn=lambda msg, hist: chat_fn(msg, hist, model_select.value),
|
| 56 |
additional_inputs=[model_select],
|
| 57 |
)
|