admin08077 commited on
Commit
088c0c6
Β·
verified Β·
1 Parent(s): 1edca48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -56,6 +56,10 @@ CONTRACT_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" # USDC Token Ad
56
  st.sidebar.subheader("πŸ€– OpenAI Configuration")
57
  OPENAI_API_KEY = st.sidebar.text_input("OpenAI API Key (Optional)", type="password")
58
 
 
 
 
 
59
  # ========================
60
  # Validate Configuration Inputs
61
  # ========================
@@ -170,12 +174,23 @@ def mint_tokens_via_api(address, token, balance):
170
  }
171
  try:
172
  response = requests.post(url, headers=headers, json=payload)
173
- if response.status_code == 200:
174
- return True, response.json()
 
 
 
 
 
 
 
 
 
175
  else:
176
- return False, response.text
177
- except Exception as e:
178
- return False, str(e)
 
 
179
 
180
  def calculate_token_grade(ai_output):
181
  """
@@ -296,7 +311,7 @@ if openai_enabled:
296
  token_amount = calculate_token_grade(ai_output)
297
  if token_amount > 0:
298
  # Mint Token via API
299
- token_address = "0xYourDefaultAddressHere" # Replace with a default or configurable address
300
  token_contract = CONTRACT_ADDRESS # Using hardcoded contract address
301
  balance = "100" # Adjust as needed
302
  mint_success, mint_response = mint_tokens_via_api(token_address, token_contract, balance)
@@ -415,7 +430,7 @@ with tabs[trading_tab_index]:
415
  st.error("❌ Token not found or unauthorized.")
416
  else:
417
  # Transfer ownership by updating recipient address
418
- token.recipient_address = "0xYourDefaultAddressHere" # Replace with your address or handle accordingly
419
  session.commit()
420
  # Update session state balance
421
  st.session_state.balance += token.value
@@ -545,9 +560,11 @@ with tabs[about_me_tab_index]:
545
  # Mint Token Functionality
546
  # ========================
547
 
548
- st.sidebar.header("πŸͺ™ Mint Token")
 
 
549
  with st.sidebar.form("mint_token_form"):
550
- mint_address = st.text_input("Recipient Address (0x...)", value="")
551
  mint_text = st.text_input("Mint Text", value="")
552
  mint_button = st.form_submit_button(label='Mint Token')
553
 
@@ -581,7 +598,6 @@ if mint_button:
581
 
582
  # Update session state balance
583
  st.session_state.balance += token.value
584
- session.commit()
585
 
586
  # Record transaction
587
  transaction = Transaction(
 
56
  st.sidebar.subheader("πŸ€– OpenAI Configuration")
57
  OPENAI_API_KEY = st.sidebar.text_input("OpenAI API Key (Optional)", type="password")
58
 
59
+ # Blockchain Address Configuration
60
+ st.sidebar.subheader("πŸ”— Your Blockchain Address")
61
+ default_token_address = st.sidebar.text_input("Your Blockchain Address (0x...)", value="0x7B35A86fa8cE689b6D8111C09217E7466B5c442A") # Example address
62
+
63
  # ========================
64
  # Validate Configuration Inputs
65
  # ========================
 
174
  }
175
  try:
176
  response = requests.post(url, headers=headers, json=payload)
177
+ # Log the status code
178
+ st.write(f"API Response Status Code: {response.status_code}")
179
+
180
+ # Check if the response contains content
181
+ if response.content:
182
+ try:
183
+ response_data = response.json()
184
+ return True, response_data
185
+ except ValueError:
186
+ st.error(f"❌ Invalid JSON response: {response.text}")
187
+ return False, f"Invalid JSON response: {response.text}"
188
  else:
189
+ st.error("❌ Empty response from the API.")
190
+ return False, "Empty response from the API."
191
+ except requests.exceptions.RequestException as e:
192
+ st.error(f"❌ Request failed: {e}")
193
+ return False, f"Request failed: {e}"
194
 
195
  def calculate_token_grade(ai_output):
196
  """
 
311
  token_amount = calculate_token_grade(ai_output)
312
  if token_amount > 0:
313
  # Mint Token via API
314
+ token_address = default_token_address # Using configurable address
315
  token_contract = CONTRACT_ADDRESS # Using hardcoded contract address
316
  balance = "100" # Adjust as needed
317
  mint_success, mint_response = mint_tokens_via_api(token_address, token_contract, balance)
 
430
  st.error("❌ Token not found or unauthorized.")
431
  else:
432
  # Transfer ownership by updating recipient address
433
+ token.recipient_address = default_token_address # Using configurable address
434
  session.commit()
435
  # Update session state balance
436
  st.session_state.balance += token.value
 
560
  # Mint Token Functionality
561
  # ========================
562
 
563
+ if 'mint_token_form' not in st.session_state:
564
+ st.session_state['mint_token_form'] = False
565
+
566
  with st.sidebar.form("mint_token_form"):
567
+ mint_address = st.text_input("Recipient Address (0x...)", value=default_token_address)
568
  mint_text = st.text_input("Mint Text", value="")
569
  mint_button = st.form_submit_button(label='Mint Token')
570
 
 
598
 
599
  # Update session state balance
600
  st.session_state.balance += token.value
 
601
 
602
  # Record transaction
603
  transaction = Transaction(