schoginitoys commited on
Commit
14a460b
1 Parent(s): aa55439
Files changed (2) hide show
  1. app.py +85 -19
  2. local.sh +1 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from datetime import datetime
3
  import smtplib
4
  import requests
 
5
  import time
6
  import examples
7
  import os
@@ -12,7 +13,7 @@ def post_it(q=''):
12
  # Define the URL and parameters
13
  if q=='':
14
  return
15
- url = os.environ.get('BLUEHOST_ENDPOINT')
16
  params = {
17
  "password": os.environ.get('BLUEHOST_API_PASS'),
18
  "q": q
@@ -36,18 +37,72 @@ def post_it(q=''):
36
  print(response)
37
  print(f"Failed to post data. Status code: {response.status_code}")
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  def greet(name):
41
  # return "Hello " + name + "!!"
42
 
43
  # Get the current date and time
44
- now = datetime.now()
45
 
46
  # Format the datetime object as a string in the format YYYYMMDD_HHMMSS
47
- timestamp_str = now.strftime("%Y%m%d_%H%M%S")
48
 
49
  # Create a unique filename by appending the timestamp to the base filename
50
- unique_filename = f"query_{timestamp_str}"
51
 
52
  #print(f"Unique Filename: {unique_filename}")
53
  #In this example, unique_filename will contain a
@@ -70,18 +125,27 @@ def greet(name):
70
 
71
  time.sleep(2)
72
 
 
 
 
 
 
 
73
  if name=='':
74
  msg="Please click any button below or enter your query."
75
  else:
76
- try:
77
- tpl=eval("examples." + name)
78
- print("examples." + name)
79
- msg = "```python\n" + tpl + "\n```\n"
80
- except:
81
- tpl=examples.THANKS #PROJECT_TEMPLATE
82
- post_it(name) # Save the query in bluehost
83
- msg = tpl
84
-
 
 
 
85
 
86
 
87
 
@@ -241,6 +305,7 @@ def sree_auth(username='', password=''):
241
 
242
  # print(os.environ.get('ABHI_PASS'))
243
  # print(os.environ.get('SREE_PASS'))
 
244
 
245
  demo = gr.Interface(
246
  # fn=CustomChatGPT,
@@ -251,12 +316,13 @@ demo = gr.Interface(
251
  title = "Schogini Toys - AI Chatbot V1.03",
252
  description="Your Python Projects Coding Companion!",
253
  allow_flagging="never",
254
- examples=[
255
- "L201",
256
- "L202",
257
- "L203",
258
- "L204",
259
- ],
 
260
  # theme=gr.themes.Soft(),
261
  theme=gr.themes.Default(),
262
  )
 
2
  from datetime import datetime
3
  import smtplib
4
  import requests
5
+ import re
6
  import time
7
  import examples
8
  import os
 
13
  # Define the URL and parameters
14
  if q=='':
15
  return
16
+ url = os.environ.get('BLUEHOST_ENDPOINT')+"/index-cb.php"
17
  params = {
18
  "password": os.environ.get('BLUEHOST_API_PASS'),
19
  "q": q
 
37
  print(response)
38
  print(f"Failed to post data. Status code: {response.status_code}")
39
 
40
+ def get_menu_item(m=''):
41
+ url = os.environ.get('BLUEHOST_ENDPOINT')+"/index-e.php"
42
+ password_token = os.environ.get('BLUEHOST_API_PASS')
43
+ headers = {
44
+ 'Accept': 'application/json',
45
+ 'Content-Type': 'application/json',
46
+ 'User-Agent': 'my-app'
47
+ }
48
+ params = {
49
+ 'password_token': password_token,
50
+ 'menu': m
51
+ }
52
+ # Make an HTTP GET request with the password token as a query parameter
53
+ response = requests.get(url, params=params, headers=headers)
54
+ # Check if the request was successful
55
+ if response.status_code == 200:
56
+ output_text = response.text
57
+ # Now, output_text contains the content fetched from the PHP script
58
+ #print(f"Received output:\n{output_text}")
59
+ return output_text
60
+ else:
61
+ #print(f"Failed to fetch data. Status code: {response.status_code}")
62
+ return ""
63
+
64
+
65
+ def get_buttons():
66
+ url = os.environ.get('BLUEHOST_ENDPOINT')+"/index-e.php"
67
+ password_token = os.environ.get('BLUEHOST_API_PASS')
68
+ headers = {
69
+ 'Accept': 'application/json',
70
+ 'Content-Type': 'application/json',
71
+ 'User-Agent': 'my-app'
72
+ }
73
+ # Make an HTTP GET request with the password token as a query parameter
74
+ response = requests.get(url, params={'password_token': password_token}, headers=headers)
75
+ # Check if the request was successful
76
+ list_values = []
77
+ if response.status_code == 200:
78
+ # Extract the plain text from the response
79
+ text_content = response.text
80
+
81
+ # Use regular expression to find all the list values, assuming they're always formatted as "Lxxx"
82
+ list_values = re.findall(r'"L\d+"', text_content)
83
+
84
+ # Remove the quotes to get the actual values
85
+ list_values = [value.strip('"') for value in list_values]
86
+
87
+ # Print or use the list
88
+ #print("Extracted list values:", list_values)
89
+
90
+ # else:
91
+ # print(f"Failed to fetch data. Status code: {response.status_code}")
92
+ # pass
93
+ return list_values
94
 
95
  def greet(name):
96
  # return "Hello " + name + "!!"
97
 
98
  # Get the current date and time
99
+ #now = datetime.now()
100
 
101
  # Format the datetime object as a string in the format YYYYMMDD_HHMMSS
102
+ #timestamp_str = now.strftime("%Y%m%d_%H%M%S")
103
 
104
  # Create a unique filename by appending the timestamp to the base filename
105
+ #unique_filename = f"query_{timestamp_str}"
106
 
107
  #print(f"Unique Filename: {unique_filename}")
108
  #In this example, unique_filename will contain a
 
125
 
126
  time.sleep(2)
127
 
128
+
129
+
130
+
131
+
132
+
133
+
134
  if name=='':
135
  msg="Please click any button below or enter your query."
136
  else:
137
+ menu_code = get_menu_item(name)
138
+ if menu_code =='':
139
+ try:
140
+ tpl=eval("examples." + name)
141
+ print("examples." + name)
142
+ msg = "```python\n" + tpl + "\n```\n"
143
+ except:
144
+ tpl=examples.THANKS #PROJECT_TEMPLATE
145
+ post_it(name) # Save the query in bluehost
146
+ msg = tpl
147
+ else:
148
+ msg = "```python\n"+menu_code+"\n```\n"
149
 
150
 
151
 
 
305
 
306
  # print(os.environ.get('ABHI_PASS'))
307
  # print(os.environ.get('SREE_PASS'))
308
+ examples_list = get_buttons()
309
 
310
  demo = gr.Interface(
311
  # fn=CustomChatGPT,
 
316
  title = "Schogini Toys - AI Chatbot V1.03",
317
  description="Your Python Projects Coding Companion!",
318
  allow_flagging="never",
319
+ examples = examples_list,
320
+ # examples=[
321
+ # "L201",
322
+ # "L202",
323
+ # "L203",
324
+ # "L204",
325
+ # ],
326
  # theme=gr.themes.Soft(),
327
  theme=gr.themes.Default(),
328
  )
local.sh CHANGED
@@ -3,6 +3,6 @@
3
  export ABHI_PASS=Abhi1234
4
  export SREE_PASS=Sree1234
5
  export BLUEHOST_API_PASS=Sree12345
6
- export BLUEHOST_ENDPOINT=https://schogini.com/cb/index-cb.php
7
 
8
  python app.py
 
3
  export ABHI_PASS=Abhi1234
4
  export SREE_PASS=Sree1234
5
  export BLUEHOST_API_PASS=Sree12345
6
+ export BLUEHOST_ENDPOINT=https://schogini.com/cb
7
 
8
  python app.py