Spaces:
Sleeping
Sleeping
deepapaikar
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
|
|
3 |
import spaces
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
7 |
|
8 |
@spaces
|
9 |
def generate_text(input_text):
|
@@ -15,11 +18,10 @@ def generate_text(input_text):
|
|
15 |
Returns:
|
16 |
str: The generated text.
|
17 |
"""
|
18 |
-
|
19 |
-
|
20 |
-
]
|
21 |
-
|
22 |
-
return output[0]['generated_text'] # Extract the generated text
|
23 |
|
24 |
iface = gr.Interface(
|
25 |
fn=generate_text,
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
import spaces
|
5 |
|
6 |
+
# Load model and tokenizer only once, outside the function
|
7 |
+
model_name = "deepapaikar/LlamaKatz-3x8B"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map='auto')
|
10 |
|
11 |
@spaces
|
12 |
def generate_text(input_text):
|
|
|
18 |
Returns:
|
19 |
str: The generated text.
|
20 |
"""
|
21 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
22 |
+
outputs = model.generate(**inputs)
|
23 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
+
return generated_text
|
|
|
25 |
|
26 |
iface = gr.Interface(
|
27 |
fn=generate_text,
|