Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,25 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
MODEL_ID = "Qwen/Qwen2.5-7B-Instruct"
|
| 5 |
|
| 6 |
-
pipe =
|
| 7 |
-
"text-generation",
|
| 8 |
-
model=MODEL_ID,
|
| 9 |
-
device_map="auto"
|
| 10 |
-
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def chat_fn(message, history):
|
| 13 |
-
|
|
|
|
| 14 |
outputs = pipe(
|
| 15 |
message,
|
| 16 |
max_new_tokens=256,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
MODEL_ID = "Qwen/Qwen2.5-7B-Instruct"
|
| 7 |
|
| 8 |
+
pipe = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def load_model():
|
| 11 |
+
global pipe
|
| 12 |
+
if pipe is None:
|
| 13 |
+
pipe = pipeline(
|
| 14 |
+
"text-generation",
|
| 15 |
+
model=MODEL_ID,
|
| 16 |
+
device_map="auto"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
@spaces.GPU
|
| 20 |
def chat_fn(message, history):
|
| 21 |
+
load_model()
|
| 22 |
+
|
| 23 |
outputs = pipe(
|
| 24 |
message,
|
| 25 |
max_new_tokens=256,
|