Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,28 @@
|
|
1 |
from transformers import pipeline
|
|
|
2 |
import streamlit as st
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
text = st.text_area('Enter Query')
|
8 |
if text:
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from transformers import pipeline
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
import streamlit as st
|
4 |
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/GODEL-v1_1-large-seq2seq")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/GODEL-v1_1-large-seq2seq")
|
7 |
+
|
8 |
+
|
9 |
+
def generate(instruction, knowledge, dialog):
|
10 |
+
if knowledge != '':
|
11 |
+
knowledge = '[KNOWLEDGE] ' + knowledge
|
12 |
+
dialog = ' EOS '.join(dialog)
|
13 |
+
query = f"{instruction} [CONTEXT] {dialog} {knowledge}"
|
14 |
+
input_ids = tokenizer(f"{query}", return_tensors="pt").input_ids
|
15 |
+
outputs = model.generate(input_ids, max_length=128, min_length=8, top_p=0.9, do_sample=True)
|
16 |
+
output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
+
return output
|
18 |
|
19 |
text = st.text_area('Enter Query')
|
20 |
if text:
|
21 |
+
# Instruction for a chitchat task
|
22 |
+
instruction = f'Using the EXAMPLE1 below, write the init(), deploy() and invariant() code for the EXAMPLE2:'
|
23 |
+
# Leave the knowldge empty
|
24 |
+
knowledge = 'EXAMPLE1:\n[\n{\n init description: [“Create a new address called “user”. Give the “user” “AMOUNT” of LP tokens. Using the “user” as the sender approve the “StaxLPStaking” contract to use his LP tokens and stake all the LP tokens into the “StaxLPStaking” contract.“],\n deploy description: [“Create a new address called “owner”. Using the “owner” as the sender deploy the “StaxLP” contract and the “StaxLPStaking” contract.“],\n invariant description: [“Using the “user” address as sender withdraw all the LP tokens from the “StaxLPStaking” contract and check the balance of the LP tokens of the “user” is not less than “AMOUNT”.“],\n init code: [{\naddress public user;\nuint256 public constant AMOUNT = 10e18;\nfunction init() public {\n user = makeAddr(“USER”);\n deal(address(lp), user, AMOUNT);\n vm.startPrank(user);\n lp.approve(address(lpStaking), lp.balanceOf(user));\n lpStaking.stakeAll();\n vm.stopPrank();\n}\n }],\n deploy code: [{\nStaxLP public lp;\nStaxLPStaking public lpStaking;\naddress public owner;\nfunction deploy() public {\n owner = makeAddr(“OWNER”);\n vm.startPrank(owner);\n lp = new StaxLP(“Stax Frax/Temple LP Token”, “xFraxTempleLP”);\n lpStaking = new StaxLPStaking(address(lp), owner);\n vm.stopPrank();\n}\n }],\n invariant code: [{\nfunction invariant() public {\n vm.prank(user);\n lpStaking.withdrawAll(false);\n assert(lp.balanceOf(user) >= AMOUNT);\n}\n }],\n}\n]'
|
25 |
+
dialog = [text]
|
26 |
+
response = generate(instruction, knowledge, dialog)
|
27 |
+
out = generator(text)
|
28 |
+
st.json(response)
|