Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ prompt1=''' is there any code Snippets present in the below text? Reply with YES
|
|
| 5 |
|
| 6 |
Text: " {} "
|
| 7 |
'''
|
| 8 |
-
prompt2='''Extract Code Snippets ONLY
|
| 9 |
|
| 10 |
Text: " {} "
|
| 11 |
'''
|
|
@@ -29,16 +29,17 @@ def chatbot_model(m,history):
|
|
| 29 |
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
if (decoded_output=='NO'):
|
| 31 |
yield 'NO'
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
# Decode the output
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
iface = gr.ChatInterface(chatbot_model,title="Code Detector",undo_btn=None,theme="soft").queue()
|
| 44 |
iface.launch()
|
|
|
|
| 5 |
|
| 6 |
Text: " {} "
|
| 7 |
'''
|
| 8 |
+
prompt2='''Extract Code Snippets ONLY.This is very important for my career:
|
| 9 |
|
| 10 |
Text: " {} "
|
| 11 |
'''
|
|
|
|
| 29 |
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 30 |
if (decoded_output=='NO'):
|
| 31 |
yield 'NO'
|
| 32 |
+
else:
|
| 33 |
+
input_ids = tokenizer.encode(prompt2.format(m) + tokenizer.eos_token, return_tensors='pt')
|
| 34 |
+
outputs = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
| 35 |
|
| 36 |
# Decode the output
|
| 37 |
+
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 38 |
+
for char, replacement in replacements.items():
|
| 39 |
+
decoded_output = decoded_output.replace(replacement, char)
|
| 40 |
+
for i in range(len(decoded_output)):
|
| 41 |
+
time.sleep(0.3)
|
| 42 |
+
yield decoded_output[:i+1]
|
| 43 |
|
| 44 |
iface = gr.ChatInterface(chatbot_model,title="Code Detector",undo_btn=None,theme="soft").queue()
|
| 45 |
iface.launch()
|