warmer / app.py
Reverent's picture
Update app.py
35ba9e8
raw
history blame
1.8 kB
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:
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"
)
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"
)
if (text_output != None) and (text_output_2 != None):
print("ALIVE")
print("pygmalion response : ", text_output)
print("qna response : ", text_output_2)
else:
print("DISCONNECTED")
time.sleep(300)
except Exception as e:
print("NO INTERNET")
print(str(e))
def restart():
while True:
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")
time.sleep(60) #Restart Space every 24 hours
except Exception as e:
print("NO INTERNET")
print(str(e))
def placeholder(dummy):
return "lol"
t = Thread(target=warmer)
r = Thread(target=restart)
t.start()
iface = gr.Interface(fn=placeholder, inputs="text", outputs="text")
iface.launch()