noteldar commited on
Commit
19fa314
1 Parent(s): 66bf55c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,10 +1,12 @@
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 != '':
@@ -22,8 +24,11 @@ text_invariant = st.text_area('Enter invariant description')
22
  if st.button('GENERATE RESPONSE'):
23
  # st.write(text_init, text_deploy, text_invariant)
24
  # Instruction
25
- instruction = f'Using the descriptions, write the init code, deploy code and invariant code'
26
- knowledge = "EXAMPLE:{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]"
27
- dialog = [f'{{init description: [“{text_init}“],\n deploy description: [“{text_deploy}“],\n invariant description: [“{text_invariant}“],\n}}']
28
- response = generate(instruction, knowledge, dialog)
 
 
 
29
  st.write(response)
 
1
+ from transformers import pipeline, set_seed
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
+ generator = pipeline('text-generation', model='gpt2')
9
+ set_seed(42)
10
 
11
  def generate(instruction, knowledge, dialog):
12
  if knowledge != '':
 
24
  if st.button('GENERATE RESPONSE'):
25
  # st.write(text_init, text_deploy, text_invariant)
26
  # Instruction
27
+
28
+ # instruction = f'Using the descriptions, write the init code, deploy code and invariant code'
29
+ # knowledge = "EXAMPLE:{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]"
30
+ # dialog = [f'{{init description: [“{text_init}“],\n deploy description: [“{text_deploy}“],\n invariant description: [“{text_invariant}“],\n}}']
31
+ # response = generate(instruction, knowledge, dialog)
32
+ PROMPT_TEXT = f'Using the EXAMPLE1 below, write the init(), deploy() and invariant() code for the EXAMPLE2:\nEXAMPLE1:\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]\nEXAMPLE2:\n{{\n init description: [“{text_init}“],\n deploy description: [“{text_deploy}“],\n invariant description: [“{text_invariant}“],\n}}'
33
+ response = generator(PROMPT_TEXT, max_length=150, num_return_sequences=1)
34
  st.write(response)