import gradio as gr import os import requests import time from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline import paddlehub as hub # Importing the essential libraries for monitoring import psutil HF_TOKEN = os.environ["HF_TOKEN"] model = hub.Module(name='ernie_vilg') def get_ernie_vilg(text_prompts, style): style = style.split('-')[0] results = model.generate_image(text_prompts=text_prompts, style=style, visualization=False) #for CPU monitoring # Testing the psutil library for both CPU and RAM performance details print(f"ERNIE CPU percent is: {psutil.cpu_percent()}") print(f"ERNIE virtual memory is : {psutil.virtual_memory().percent}") return results[0] sd_inf = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion", use_auth_token=HF_TOKEN) nllb_model_name = 'facebook/nllb-200-distilled-600M' nllb_model = AutoModelForSeq2SeqLM.from_pretrained(nllb_model_name) nllb_tokenizer = AutoTokenizer.from_pretrained(nllb_model_name) def get_chinese_translation(text): #in_language_first, in_language_second, print("********Inside get_chinese_translation ********") src = 'eng_Latn' tgt= 'zho_Hans' print(f"text is :{text}, source language is : {src}, target language is : {tgt} ") translator = pipeline('translation', model=nllb_model, tokenizer=nllb_tokenizer, src_lang=src, tgt_lang=tgt) output = translator(text, max_length=400) print(f"initial output is:{output}") output = output[0]['translation_text'] print(f"output is:{output}") # for CPU monitoring # Testing the psutil library for both CPU and RAM performance details print(f"CPU percent is: {psutil.cpu_percent()}") print(f"virtual memory is : {psutil.virtual_memory().percent}") return output #Block inference not working for stable diffusion def get_sd(translated_txt, samples, steps, scale, seed): print("******** Inside get_SD ********") print(f"translated_txt is : {translated_txt}") sd_img_gallery = sd_inf(translated_txt, samples, steps, scale, seed, fn_index=1)[0] return sd_img_gallery demo = gr.Blocks() with demo: gr.Markdown("