RoAr777 commited on
Commit
cfb525b
·
1 Parent(s): aa4f94d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -2,17 +2,26 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
  import time
3
  import gradio as gr
4
 
5
- #model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-ul2")
6
- #tokenizer = AutoTokenizer.from_pretrained("google/flan-ul2")
7
 
8
 
9
 
10
 
11
 
12
 
13
- def slow_echo(message, history):
14
- for i in range(len(message)):
 
 
 
 
 
 
 
 
 
15
  time.sleep(0.3)
16
- yield "You typed: " + message[: i+1]
17
 
18
- gr.ChatInterface(slow_echo).queue().launch()
 
2
  import time
3
  import gradio as gr
4
 
5
+ model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-ul2")
6
+ tokenizer = AutoTokenizer.from_pretrained("google/flan-ul2")
7
 
8
 
9
 
10
 
11
 
12
 
13
+ prompt=''' Review the Following text as a human, who is tasked to Extract `Code Snippets` ,if any. If there are no Code Snippets in the below Text then return No CODE HIDDEN:
14
+
15
+ "{}"
16
+ '''
17
+ def reply(message, history):
18
+ m=message.replace('\n','')
19
+ m=m.replace('\t','')
20
+ inputs = tokenizer(prompt.format(m), return_tensors="pt")
21
+ outputs = model.generate(**inputs)
22
+ code=tokenizer.batch_decode(outputs, skip_special_tokens=True)
23
+ for i in range(len(code)):
24
  time.sleep(0.3)
25
+ yield code[: i+1]
26
 
27
+ gr.ChatInterface(reply).queue().launch()