Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,26 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
| 2 |
import time
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
time.sleep(0.3)
|
| 16 |
-
yield
|
| 17 |
|
| 18 |
-
gr.ChatInterface(
|
|
|
|
| 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()
|