from newsapi import NewsApiClient from gradio_client import Client # example input: prompt = "Beautiful Sky with "Gradio is love" written over it" # defining a function to generate music using Gradio demo of TextDiffusers hosted on Spaces def generate_image(prompt: str) -> str: """ generate an image based on the prompt provided """ #client = Client("https://jingyechen22-textdiffuser.hf.space/") client = Client("https://ysharma-textdiffuser.hf.space/", hf_token="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") result = client.predict( prompt, # str in 'Input your prompt here. Please enclose keywords with 'single quotes', you may refer to the examples below. The current version only supports input in English characters.' Textbox component 20, # int | float (numeric value between 1 and 50) in 'Sampling step' Slider component 7.5, # int | float (numeric value between 1 and 9) in 'Scale of classifier-free guidance' Slider component 1, # int | float (numeric value between 1 and 4) in 'Batch size' Slider component "Stable Diffusion v2.1", # str in 'Pre-trained Model' Radio component fn_index=1) return result[0] # example input: input_image = "cat.jpg" # defining a function to generate caption using a image caption Gradio demo hosted on Spaces def generate_caption(input_image ): """ generate caption for the input image """ client = Client("https://nielsr-comparing-captioning-models.hf.space/") temp = input_image.split('/') if len(temp) == 1: input_image = temp[0] else: input_image = temp[-1] result = client.predict( input_image, api_name="/predict") result = "The image can have any one of the following captions, all captions are correct: " + ", or ".join([f"'{caption.replace('.','')}'" for caption in result]) return result # defining a function to get the most relevant world news for a given query # example query: Joe Biden presidency def get_news(search_query): """ get top three news items for your search query """ newsapi = NewsApiClient(api_key='8c50d2b3d80348a2a78be021b2c49cd1') docs = newsapi.get_everything(q=search_query, language='en', sort_by = 'relevancy', page_size=3, page=1 )['articles'] res = [news['description'] for news in docs] res = [item.replace('
  • ','').replace('
  • ','').replace('
      ','') for item in res] res = "\n".join([f"{i}.{ res[i-1]}" for i in range(1,len(res)+1)]) return "Following list has the top three news items for the given search query : \n" + res