Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
model_checkpoint = "distilgpt2"
|
5 |
+
model_checkpoint_amal = "Amal17/wikipedia-20230601.ace"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, use_fast=True, trust_remote_code=True)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_checkpoint_amal,
|
10 |
+
trust_remote_code=True
|
11 |
+
)
|
12 |
+
|
13 |
+
model.eval()
|
14 |
+
|
15 |
+
def generate(input):
|
16 |
+
inputs = tokenizer(input, return_tensors="pt")
|
17 |
+
r = model.generate(
|
18 |
+
inputs=inputs.input_ids,
|
19 |
+
# streamer=streamer,
|
20 |
+
pad_token_id=tokenizer.pad_token_id,
|
21 |
+
eos_token_id=tokenizer.eos_token_id,
|
22 |
+
# max_length=256,
|
23 |
+
# temperature=0.7,
|
24 |
+
# do_sample=True,
|
25 |
+
# # top_k=4,
|
26 |
+
# top_p=0.95
|
27 |
+
max_new_tokens=35
|
28 |
+
)
|
29 |
+
output = tokenizer.decode(r[0])
|
30 |
+
|
31 |
+
|
32 |
+
return output
|
33 |
+
|
34 |
+
iface = gr.Interface(fn=generate, inputs="text", outputs="text")
|
35 |
+
iface.launch()
|