Abdulmohsena commited on
Commit
527dced
·
verified ·
1 Parent(s): 6a064fc

Add logging of outputs

Browse files
Files changed (1) hide show
  1. app.py +17 -13
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", revision="03226648afb02523acacfe8af1363cc5ddd9e795").to(device)
 
 
14
 
15
- def translate(text, temperature=0.1, tries=1):
16
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256).to(device)
17
- outputs = model.generate(
18
- **inputs,
19
- do_sample=True,
20
- temperature=temperature,
21
- num_return_sequences=tries,
22
- )
23
- translation = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
 
25
- return translation
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__":