File size: 2,324 Bytes
e598102 08bacf4 de57008 4a07312 08bacf4 95b01e8 72ecf70 e6b327f 096633b b2f3eb6 e598102 e6b327f 46a75dc b60344d 0ca3c8c a884ae1 e6b327f d26b817 de4a9bf d26b817 e6b327f 46a75dc b60344d a23fb06 e6b327f d26b817 72ecf70 21035b9 d26b817 72ecf70 3abfbb6 72ecf70 08bacf4 3abfbb6 35ba9e8 e6b327f e09a781 e6b327f f8bf3fe 35ba9e8 10b0e75 4ac0888 10b0e75 a7586a8 4a07312 4ac0888 4389075 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
from gradio_client import Client
import time
import os
import gradio as gr
from threading import Thread
print("RAN")
hf_token_id = os.environ['TOKEN']
client = Client("Reverent/ATLEI2",hf_token=hf_token_id)
def warmer():
while True:
try:
start_time = time.time()
text_output,image_output = client.predict(
"atleiwarm0001", # str in 'message' Textbox component
"", # str (filepath or URL to image) in 'Upload any Image' Image component
api_name="/predict"
)
end_time = time.time()
duration = end_time - start_time
print("Time elapsed for Mistral model : ", duration)
if duration > 90: # Check if duration to generate tokens exceeds 1 minutes
restart()
start_time = time.time()
text_output_2,image_output_2 = client.predict(
"atleiwarm0002", # str in 'message' Textbox component
"", # str (filepath or URL to image) in 'Upload any Image' Image component
api_name="/predict"
)
end_time = time.time()
duration = end_time - start_time
print("Time elapsed for Starling model : ", duration)
if duration > 90: # Check if duration to generate tokens exceeds 1.4 minutes
restart()
if (text_output != None) and (text_output_2 != None):
print("ALIVE")
print("mistral response : ", text_output)
print("qna response : ", text_output_2)
else:
print("DISCONNECTED")
except Exception as e:
print("NO INTERNET")
print(str(e))
time.sleep(300)
def restart():
try:
text_output,image_output = client.predict(
"atleiwarm0003", # str in 'message' Textbox component
"", # str (filepath or URL to image) in 'Upload any Image' Image component
api_name="/predict"
)
print("RESTARTED")
except Exception as e:
print("NO INTERNET")
print(str(e))
return
def placeholder(dummy):
return "lol"
t = Thread(target=warmer)
t.start()
iface = gr.Interface(fn=placeholder, inputs="text", outputs="text")
iface.launch(show_error=True)
|