Spaces:
Sleeping
Sleeping
Add logging of outputs
Browse files
app.py
CHANGED
@@ -1,28 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
import torch
|
6 |
import warnings
|
|
|
|
|
|
|
7 |
|
8 |
warnings.filterwarnings("ignore")
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
|
11 |
# Load the tokenizer and model
|
12 |
tokenizer = AutoTokenizer.from_pretrained("Abdulmohsena/Faseeh")
|
13 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("Abdulmohsena/Faseeh"
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
**inputs,
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
|
27 |
# Gradio interface
|
28 |
with gr.Blocks() as demo:
|
@@ -38,7 +42,7 @@ with gr.Blocks() as demo:
|
|
38 |
translate_btn = gr.Button("Translate")
|
39 |
|
40 |
# Button action
|
41 |
-
translate_btn.click(translate, inputs=input_text, outputs=output_text)
|
42 |
|
43 |
# Launch the Gradio app
|
44 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
import torch
|
5 |
import warnings
|
6 |
+
import weave
|
7 |
+
|
8 |
+
weave.init("Faseeh")
|
9 |
|
10 |
warnings.filterwarnings("ignore")
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
|
13 |
# Load the tokenizer and model
|
14 |
tokenizer = AutoTokenizer.from_pretrained("Abdulmohsena/Faseeh")
|
15 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Abdulmohsena/Faseeh").to(device)
|
16 |
+
|
17 |
+
class Faseeh(weave.Model):
|
18 |
|
19 |
+
@weave.op()
|
20 |
+
def translate(self, input_data: str, temperature: float = 0.1):
|
21 |
+
inputs = tokenizer(input_data, return_tensors='pt')
|
22 |
+
outputs = model.generate(**inputs,
|
23 |
+
temperature=temperature,
|
24 |
+
do_sample=True)[0]
|
25 |
+
prediction = tokenizer.decode(outputs, skip_special_tokens=True)
|
26 |
+
|
27 |
+
return prediction
|
28 |
|
29 |
+
faseeh = Faseeh()
|
30 |
|
31 |
# Gradio interface
|
32 |
with gr.Blocks() as demo:
|
|
|
42 |
translate_btn = gr.Button("Translate")
|
43 |
|
44 |
# Button action
|
45 |
+
translate_btn.click(faseeh.translate, inputs=input_text, outputs=output_text)
|
46 |
|
47 |
# Launch the Gradio app
|
48 |
if __name__ == "__main__":
|