Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +25 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 2 |
+
import time
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-xl")
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-xl")
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
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:
|
| 12 |
+
|
| 13 |
+
"{}"
|
| 14 |
+
'''
|
| 15 |
+
def reply(message, history):
|
| 16 |
+
m=message.replace('\n','')
|
| 17 |
+
m=m.replace('\t','')
|
| 18 |
+
inputs = tokenizer(prompt.format(m), return_tensors="pt")
|
| 19 |
+
outputs = model.generate(**inputs)
|
| 20 |
+
code=tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 21 |
+
for i in range(len(code)):
|
| 22 |
+
time.sleep(0.3)
|
| 23 |
+
yield code[: i+1]
|
| 24 |
+
|
| 25 |
+
gr.ChatInterface(slow_echo).queue().launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
time
|
| 3 |
+
gradio
|