Spaces:
Running
on
Zero
Running
on
Zero
feat: another simple approach
Browse files
app.py
CHANGED
@@ -1,33 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
-
|
4 |
-
import
|
5 |
-
|
6 |
-
# Configure logging
|
7 |
-
logging.basicConfig(level=logging.INFO)
|
8 |
-
|
9 |
-
# Load model and tokenizer using pipeline
|
10 |
-
logging.info("Loading model and tokenizer...")
|
11 |
-
model_name = "speakleash/Bielik-11B-v2.3-Instruct"
|
12 |
-
pipe = pipeline("text-generation", model=model_name)
|
13 |
|
14 |
|
15 |
@spaces.GPU
|
16 |
-
def
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
hardcoded_prompt = "Stwórz zwięzłe podsumowanie tekstu, zachowując kluczowe punkty. Maksymalnie 3 zdania"
|
25 |
-
combined_text = hardcoded_prompt + text
|
26 |
-
return process_text(combined_text)
|
27 |
|
28 |
|
29 |
-
gr.Interface(
|
30 |
-
|
31 |
-
inputs=gr.Text(),
|
32 |
-
outputs=gr.Text(),
|
33 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
@spaces.GPU
|
8 |
+
def test():
|
9 |
+
device = torch.device("cuda")
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained("speakleash/Bielik-7B-Instruct-v0.1")
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(
|
12 |
+
"speakleash/Bielik-7B-Instruct-v0.1-GGUF",
|
13 |
+
model_file="bielik-7b-instruct-v0.1.Q4_K_M.gguf",
|
14 |
+
model_type="mistral", gpu_layers=50, hf=True).to(device)
|
15 |
+
|
16 |
+
inputs = tokenizer("Cześć Bielik, jak się masz?", return_tensors="pt").to(device)
|
17 |
|
18 |
+
with torch.no_grad():
|
19 |
+
outputs = model.generate(
|
20 |
+
**inputs, max_new_tokens=128, pad_token_id=tokenizer.eos_token_id
|
21 |
+
)
|
22 |
|
23 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
24 |
|
25 |
|
26 |
+
demo = gr.Interface(fn=test, inputs=None, outputs=gr.Text())
|
27 |
+
demo.launch()
|
|
|
|
|
|