|
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("https://reverent-atlei2.hf.space/",hf_token=hf_token_id) |
|
def warmer(): |
|
while True: |
|
try: |
|
start_time = time.time() |
|
text_output,image_output = client.predict( |
|
"atleiwarm0001", |
|
"", |
|
api_name="/predict" |
|
) |
|
end_time = time.time() |
|
duration = end_time - start_time |
|
print("Time elapsed for Mistral model : ", duration) |
|
if duration > 90: |
|
restart() |
|
|
|
start_time = time.time() |
|
text_output_2,image_output_2 = client.predict( |
|
"atleiwarm0002", |
|
"", |
|
api_name="/predict" |
|
) |
|
end_time = time.time() |
|
duration = end_time - start_time |
|
print("Time elapsed for Starling model : ", duration) |
|
if duration > 90: |
|
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", |
|
"", |
|
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() |
|
|