Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,27 @@
|
|
1 |
-
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
import torch
|
4 |
|
5 |
# Load tokenizer and model
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
7 |
-
model = AutoModelForCausalLM.from_pretrained("
|
8 |
|
9 |
-
#
|
10 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
model.to(device)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
output = model.generate(
|
17 |
-
input_ids,
|
18 |
-
max_length=max_length,
|
19 |
-
do_sample=True,
|
20 |
-
temperature=temperature,
|
21 |
-
top_k=50,
|
22 |
-
top_p=0.95
|
23 |
-
)
|
24 |
-
result = tokenizer.decode(output[0], skip_special_tokens=True)
|
25 |
-
return result
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
outputs="text",
|
36 |
-
title="Myanmarsar-GPT Text Generator",
|
37 |
-
description="Type Burmese text and let the model generate a continuation."
|
38 |
)
|
39 |
|
40 |
-
|
|
|
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import torch
|
3 |
|
4 |
# Load tokenizer and model
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("simbolo-ai/Myanmarsar-GPT")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("simbolo-ai/Myanmarsar-GPT")
|
7 |
|
8 |
+
# Move model to GPU if available
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
10 |
model.to(device)
|
11 |
|
12 |
+
# Input text
|
13 |
+
input_text = "Marketing"
|
14 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt').to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Generate output
|
17 |
+
output = model.generate(
|
18 |
+
input_ids,
|
19 |
+
max_length=256,
|
20 |
+
do_sample=True,
|
21 |
+
temperature=0.7,
|
22 |
+
top_k=50,
|
23 |
+
top_p=0.95
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
+
# Decode and print
|
27 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|