rishi1985 commited on
Commit
c9fdfac
1 Parent(s): 035463c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -56
app.py CHANGED
@@ -90,6 +90,7 @@ async def startup_event():
90
 
91
  # LLAMA
92
 
 
93
 
94
  @app.post("/llama")
95
  async def get_answer_llama(request: Request ):
@@ -105,17 +106,15 @@ async def get_answer_llama(request: Request ):
105
 
106
 
107
 
108
-
109
-
110
  def do_ML_LLAMA(text:str, trycount:int):
111
  starttime=time.time()
112
  options = ChromeOptions()
113
  options.add_argument('--no-sandbox')
114
  options.add_argument('-headless')
115
  options.add_argument("start-maximized")
116
- service = Service()
117
  driver = webdriver.Chrome(options= options,service=service)
118
- driver.get("https://ysharma-explore-llamav2-with-tgi.hf.space/")
119
  try:
120
 
121
  while True:
@@ -123,42 +122,37 @@ def do_ML_LLAMA(text:str, trycount:int):
123
  if(currtime>starttime+20):
124
  return "Requested Could not be proceed"
125
  try:
126
- textarea_xpath = "//textarea[@data-testid='textbox' and @class='scroll-hide svelte-1kcgrqr' and @dir='ltr' and @placeholder='Type a message...']"
127
- textarea_element = driver.find_element(By.XPATH,textarea_xpath)
128
 
129
  for line in text.split('\n'):
130
  textarea_element.send_keys(line)
131
  # Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
132
  textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
 
 
 
 
 
 
 
 
 
 
133
 
134
  break
135
  except:
136
  continue
137
- while True:
138
- currtime= time.time()
139
- if(currtime>starttime+20):
140
- return "Requested Could not be proceed"
141
-
142
- try:
143
- button_id = 'component-10'
144
- button_element = driver.find_element(By.ID,button_id)
145
-
146
- button_element.click()
147
- # print("sent hii")
148
- break
149
- except Exception as e:
150
- print(e)
151
- time.sleep(0.2)
152
 
153
 
154
  prev =""
155
 
156
- # time.sleep(2)
157
  while True:
158
  time.sleep(0.5)
159
  currtime= time.time()
160
 
161
- if(currtime>starttime+120):
162
  driver.delete_all_cookies()
163
  driver.quit()
164
 
@@ -166,35 +160,14 @@ def do_ML_LLAMA(text:str, trycount:int):
166
 
167
  # value=""
168
  try:
 
169
  element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
170
- print(element.text)
171
- # Extract the text from the div element
172
- text = element.text
173
- # print("text from llama",text)
174
-
175
-
176
-
177
- if prev!="":
178
-
179
- try:
180
- element_translucent = driver.find_element(By.XPATH,'//div[contains(@class, "translucent") and contains(@class, "generating")]')
181
- continue
182
- except:
183
- pass
184
-
185
- driver.delete_all_cookies()
186
- driver.quit()
187
- return text
188
- prev= text
189
  continue
190
-
191
-
192
-
193
 
194
- except Exception as e:
195
- print(e)
196
- continue
197
-
198
 
199
 
200
 
@@ -203,16 +176,11 @@ def do_ML_LLAMA(text:str, trycount:int):
203
 
204
 
205
  except:
206
- print("Error")
207
-
208
- if trycount>1:
209
-
210
- return
211
- driver.quit()
212
- return do_ML_LLAMA(text,trycount+1)
213
 
214
 
215
 
 
216
  ########## MPT
217
 
218
 
 
90
 
91
  # LLAMA
92
 
93
+ chrome_driver_path = '/usr/local/bin/chromedriver'
94
 
95
  @app.post("/llama")
96
  async def get_answer_llama(request: Request ):
 
106
 
107
 
108
 
 
 
109
  def do_ML_LLAMA(text:str, trycount:int):
110
  starttime=time.time()
111
  options = ChromeOptions()
112
  options.add_argument('--no-sandbox')
113
  options.add_argument('-headless')
114
  options.add_argument("start-maximized")
115
+ service = Service(executable_path=chrome_driver_path)
116
  driver = webdriver.Chrome(options= options,service=service)
117
+ driver.get("https://huggingface-projects-llama-2-7b-chat.hf.space")
118
  try:
119
 
120
  while True:
 
122
  if(currtime>starttime+20):
123
  return "Requested Could not be proceed"
124
  try:
125
+ xpath_expression = '//textarea[@data-testid="textbox"]'
126
+ textarea_element = driver.find_element(By.XPATH, xpath_expression)
127
 
128
  for line in text.split('\n'):
129
  textarea_element.send_keys(line)
130
  # Simulate pressing the 'Shift + Enter' keys to add a newline without triggering submit
131
  textarea_element.send_keys(Keys.SHIFT + Keys.ENTER)
132
+
133
+ span_element = driver.find_element(By.CLASS_NAME, 'svelte-s1r2yt')
134
+
135
+ span_element.click()
136
+ input_element = driver.find_element(By.CSS_SELECTOR, 'input[data-testid="number-input"]')
137
+ new_value = "2048" # Replace this with the value you want to set
138
+ input_element.clear()
139
+ input_element.send_keys(new_value)
140
+
141
+ textarea_element.send_keys('\n')
142
 
143
  break
144
  except:
145
  continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
 
148
  prev =""
149
 
150
+ time.sleep(0.6)
151
  while True:
152
  time.sleep(0.5)
153
  currtime= time.time()
154
 
155
+ if(currtime>starttime+170):
156
  driver.delete_all_cookies()
157
  driver.quit()
158
 
 
160
 
161
  # value=""
162
  try:
163
+ div_element = driver.find_element(By.CLASS_NAME, 'wrap.default.minimal.svelte-zlszon.translucent.hide')
164
  element = driver.find_element(By.XPATH,'//div[@data-testid="bot" and contains(@class, "message bot")]')
165
+
166
+ x=(element.text)
167
+ return x
168
+ except:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  continue
 
 
 
170
 
 
 
 
 
171
 
172
 
173
 
 
176
 
177
 
178
  except:
179
+ return "Error Occurred "
 
 
 
 
 
 
180
 
181
 
182
 
183
+
184
  ########## MPT
185
 
186