fugthchat commited on
Commit
36161ba
Β·
verified Β·
1 Parent(s): ce256f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -23
app.py CHANGED
@@ -9,7 +9,8 @@ import streamlit.components.v1 as components
9
  st.set_page_config(layout="wide", page_title="Vivara Remix", page_icon="⚑")
10
 
11
  # CSS HACKS TO MAKE IT LOOK LIKE AN IDE
12
- st.markdown("""
 
13
  <style>
14
  /* Main Background to Dark Gray */
15
  .stApp { background-color: #1a1a1a; color: #ffffff; }
@@ -50,22 +51,65 @@ st.markdown("""
50
  font-size: 12px;
51
  }
52
  </style>
53
- """, unsafe_allow_html=True)
 
 
54
 
55
  # --- 2. SIDEBAR (FILE EXPLORER) ---
56
  with st.sidebar:
57
  st.image("https://api.dicebear.com/7.x/shapes/svg?seed=vivara", width=40)
58
  st.caption("Vivara Forge v2.0.1")
59
-
60
  st.markdown("### πŸ“‚ File Explorer")
61
  st.markdown("πŸ“„ **Vivara.sol**")
62
  st.markdown("πŸ“„ *Token.sol*")
63
  st.markdown("πŸ“ *artifacts/*")
64
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  st.divider()
66
-
67
  st.markdown("### βš™οΈ Environment")
68
- env = st.selectbox("Environment", ["Injected Provider - MetaMask", "Vivara VM (London)", "Vivara VM (Berlin)"])
 
 
 
69
  st.text_input("Account", value="0x... (Connect Wallet)", disabled=True)
70
  st.number_input("Gas Limit", value=3000000)
71
  st.text_input("Value (Wei)", value="0")
@@ -85,31 +129,40 @@ import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
85
  // 🦁 THE VIVARA PROTOCOL
86
  contract VivaraToken is ERC20 {
87
  constructor() ERC20("Vivara", "VIVR") {
 
 
88
  _mint(msg.sender, 1000000000 * 10**18);
89
  }
90
  }"""
91
- code = st.text_area("Write Solidity Code", value=default_sol, height=550, label_visibility="collapsed")
 
 
 
 
 
92
 
93
  # --- RIGHT: TOOLS PANEL ---
94
  with col_tools:
95
  tab_compile, tab_deploy = st.tabs(["Compile", "Deploy"])
96
-
97
  # TAB 1: COMPILER
98
  with tab_compile:
99
  st.markdown("##### Solidity Compiler")
100
  st.selectbox("Compiler Version", ["0.8.20", "0.8.19", "0.8.18"])
101
  st.checkbox("Auto compile", value=True)
102
  st.checkbox("Enable Optimization")
103
-
104
  if st.button("Compile Vivara.sol", type="primary", use_container_width=True):
105
  with st.spinner("Compiling..."):
106
  try:
107
- install_solc('0.8.20')
108
- compiled = compile_source(code, output_values=['abi', 'bin'], solc_version='0.8.20')
 
 
109
  contract_id, iface = list(compiled.items())[-1]
110
- st.session_state['abi'] = iface['abi']
111
- st.session_state['bin'] = iface['bin']
112
- st.session_state['name'] = contract_id
113
  st.success(f"βœ… Compiled")
114
  except Exception as e:
115
  st.error("Compilation Failed")
@@ -118,14 +171,14 @@ with col_tools:
118
  # TAB 2: DEPLOYER
119
  with tab_deploy:
120
  st.markdown("##### Deploy & Run")
121
-
122
- if 'bin' in st.session_state:
123
  st.markdown(f"**Contract:** {st.session_state['name']}")
124
-
125
  # THE ORANGE BUTTON (Remix Style)
126
- abi_json = json.dumps(st.session_state['abi'])
127
- bytecode = st.session_state['bin']
128
-
129
  html_script = f"""
130
  <html>
131
  <head><script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"></script></head>
@@ -171,7 +224,7 @@ with col_tools:
171
  </html>
172
  """
173
  components.html(html_script, height=100)
174
-
175
  st.markdown("---")
176
  st.caption("Deployed Contracts:")
177
  st.markdown(f"`{st.session_state['name']} at 0x...`")
@@ -180,11 +233,14 @@ with col_tools:
180
 
181
  # --- 4. BOTTOM TERMINAL (LOGS) ---
182
  st.markdown("#### πŸ“Ÿ Terminal")
183
- st.markdown("""
 
184
  <div class="terminal">
185
  [INFO] Welcome to Vivara Forge v2.0.1<br>
186
  [INFO] Connected to Hugging Face Cloud Engine<br>
187
  [INFO] Environment: Injected Web3<br>
188
  > _
189
  </div>
190
- """, unsafe_allow_html=True)
 
 
 
9
  st.set_page_config(layout="wide", page_title="Vivara Remix", page_icon="⚑")
10
 
11
  # CSS HACKS TO MAKE IT LOOK LIKE AN IDE
12
+ st.markdown(
13
+ """
14
  <style>
15
  /* Main Background to Dark Gray */
16
  .stApp { background-color: #1a1a1a; color: #ffffff; }
 
51
  font-size: 12px;
52
  }
53
  </style>
54
+ """,
55
+ unsafe_allow_html=True,
56
+ )
57
 
58
  # --- 2. SIDEBAR (FILE EXPLORER) ---
59
  with st.sidebar:
60
  st.image("https://api.dicebear.com/7.x/shapes/svg?seed=vivara", width=40)
61
  st.caption("Vivara Forge v2.0.1")
62
+
63
  st.markdown("### πŸ“‚ File Explorer")
64
  st.markdown("πŸ“„ **Vivara.sol**")
65
  st.markdown("πŸ“„ *Token.sol*")
66
  st.markdown("πŸ“ *artifacts/*")
67
+
68
+ <style>
69
+ /* Strip Streamlit chrome */
70
+ header { visibility: hidden; }
71
+ footer { visibility: hidden; }
72
+ .stApp { background-color: #0e1117; color: #e6e8ec; }
73
+ section[data-testid="stSidebar"] { background-color: #141821; border-right: 1px solid #1f2530; }
74
+ .block-container { padding-top: 0.5rem; padding-bottom: 0rem; }
75
+
76
+ /* Editor Look */
77
+ .stTextArea textarea {
78
+ font-family: 'JetBrains Mono', 'Courier New', monospace;
79
+ background-color: #1e1e1e;
80
+ color: #d4d4d4;
81
+ border: 1px solid #333;
82
+ }
83
+
84
+ /* Buttons Remix Style */
85
+ .stButton button {
86
+ background-color: #2f3136;
87
+ color: white;
88
+ border: 1px solid #444;
89
+ border-radius: 4px;
90
+ font-size: 14px;
91
+ }
92
+ .stButton button:hover { background-color: #36393f; border-color: #00ff41; }
93
+
94
+ /* Terminal Area */
95
+ .terminal {
96
+ background-color: #000000;
97
+ color: #00ff41;
98
+ font-family: 'JetBrains Mono', monospace;
99
+ padding: 10px;
100
+ border-top: 1px solid #333;
101
+ height: 150px;
102
+ overflow-y: scroll;
103
+ font-size: 12px;
104
+ }
105
+ </style>
106
  st.divider()
107
+
108
  st.markdown("### βš™οΈ Environment")
109
+ env = st.selectbox(
110
+ "Environment",
111
+ ["Injected Provider - MetaMask", "Vivara VM (London)", "Vivara VM (Berlin)"],
112
+ )
113
  st.text_input("Account", value="0x... (Connect Wallet)", disabled=True)
114
  st.number_input("Gas Limit", value=3000000)
115
  st.text_input("Value (Wei)", value="0")
 
129
  // 🦁 THE VIVARA PROTOCOL
130
  contract VivaraToken is ERC20 {
131
  constructor() ERC20("Vivara", "VIVR") {
132
+ st.markdown("### 🦊 Wallet")
133
+ st.caption("Use injected MetaMask in browser")
134
  _mint(msg.sender, 1000000000 * 10**18);
135
  }
136
  }"""
137
+ code = st.text_area(
138
+ "Write Solidity Code",
139
+ value=default_sol,
140
+ height=550,
141
+ label_visibility="collapsed",
142
+ )
143
 
144
  # --- RIGHT: TOOLS PANEL ---
145
  with col_tools:
146
  tab_compile, tab_deploy = st.tabs(["Compile", "Deploy"])
147
+
148
  # TAB 1: COMPILER
149
  with tab_compile:
150
  st.markdown("##### Solidity Compiler")
151
  st.selectbox("Compiler Version", ["0.8.20", "0.8.19", "0.8.18"])
152
  st.checkbox("Auto compile", value=True)
153
  st.checkbox("Enable Optimization")
154
+
155
  if st.button("Compile Vivara.sol", type="primary", use_container_width=True):
156
  with st.spinner("Compiling..."):
157
  try:
158
+ install_solc("0.8.20")
159
+ compiled = compile_source(
160
+ code, output_values=["abi", "bin"], solc_version="0.8.20"
161
+ )
162
  contract_id, iface = list(compiled.items())[-1]
163
+ st.session_state["abi"] = iface["abi"]
164
+ st.session_state["bin"] = iface["bin"]
165
+ st.session_state["name"] = contract_id
166
  st.success(f"βœ… Compiled")
167
  except Exception as e:
168
  st.error("Compilation Failed")
 
171
  # TAB 2: DEPLOYER
172
  with tab_deploy:
173
  st.markdown("##### Deploy & Run")
174
+
175
+ if "bin" in st.session_state:
176
  st.markdown(f"**Contract:** {st.session_state['name']}")
177
+
178
  # THE ORANGE BUTTON (Remix Style)
179
+ abi_json = json.dumps(st.session_state["abi"])
180
+ bytecode = st.session_state["bin"]
181
+
182
  html_script = f"""
183
  <html>
184
  <head><script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"></script></head>
 
224
  </html>
225
  """
226
  components.html(html_script, height=100)
227
+
228
  st.markdown("---")
229
  st.caption("Deployed Contracts:")
230
  st.markdown(f"`{st.session_state['name']} at 0x...`")
 
233
 
234
  # --- 4. BOTTOM TERMINAL (LOGS) ---
235
  st.markdown("#### πŸ“Ÿ Terminal")
236
+ st.markdown(
237
+ """
238
  <div class="terminal">
239
  [INFO] Welcome to Vivara Forge v2.0.1<br>
240
  [INFO] Connected to Hugging Face Cloud Engine<br>
241
  [INFO] Environment: Injected Web3<br>
242
  > _
243
  </div>
244
+ """,
245
+ unsafe_allow_html=True,
246
+ )