ysharma HF staff commited on
Commit
ae72a48
1 Parent(s): bd9076a

added bored_api function def

Browse files
Files changed (1) hide show
  1. gpt_function_definitions.py +42 -1
gpt_function_definitions.py CHANGED
@@ -1,5 +1,7 @@
1
  from newsapi import NewsApiClient
2
  from gradio_client import Client
 
 
3
 
4
  # example input: prompt = "Beautiful Sky with "Gradio is love" written over it"
5
  # defining a function to generate music using Gradio demo of TextDiffusers hosted on Spaces
@@ -7,7 +9,6 @@ def generate_image(prompt: str) -> str:
7
  """
8
  generate an image based on the prompt provided
9
  """
10
- #client = Client("https://jingyechen22-textdiffuser.hf.space/")
11
  client = Client("https://ysharma-textdiffuser.hf.space/", hf_token="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")
12
  result = client.predict(
13
  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
@@ -18,6 +19,26 @@ def generate_image(prompt: str) -> str:
18
  fn_index=1)
19
  return result[0]
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # example input: input_image = "cat.jpg"
23
  # defining a function to generate caption using a image caption Gradio demo hosted on Spaces
@@ -56,3 +77,23 @@ def get_news(search_query):
56
  res = "\n".join([f"{i}.{ res[i-1]}" for i in range(1,len(res)+1)])
57
  return "Following list has the top three news items for the given search query : \n" + res
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from newsapi import NewsApiClient
2
  from gradio_client import Client
3
+ import requests
4
+ import random
5
 
6
  # example input: prompt = "Beautiful Sky with "Gradio is love" written over it"
7
  # defining a function to generate music using Gradio demo of TextDiffusers hosted on Spaces
 
9
  """
10
  generate an image based on the prompt provided
11
  """
 
12
  client = Client("https://ysharma-textdiffuser.hf.space/", hf_token="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")
13
  result = client.predict(
14
  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
 
19
  fn_index=1)
20
  return result[0]
21
 
22
+ # example input: input_text = "A cheerful country song with acoustic guitars"
23
+ # defining a function to generate music using Gradio demo of MusicGen hosted on Spaces
24
+ #input melody example = "/content/bolero_ravel.mp3"
25
+ def generate_music(input_text, input_melody ):
26
+ """
27
+ generate music based on an input text
28
+ """
29
+ client = Client("https://ysharma-musicgendupe.hf.space/", hf_token="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")
30
+ result = client.predict(
31
+ "melody", # str in 'Model' Radio component
32
+ input_text, # str in 'Input Text' Textbox component
33
+ input_melody, # str (filepath or URL to file) in 'Melody Condition (optional)' Audio component
34
+ 5, # int | float (numeric value between 1 and 120) in 'Duration' Slider component
35
+ 250, # int | float in 'Top-k' Number component
36
+ 0, # int | float in 'Top-p' Number component
37
+ 1, # int | float in 'Temperature' Number component
38
+ 3, # int | float in 'Classifier Free Guidance' Number component
39
+ fn_index=1)
40
+ return result
41
+
42
 
43
  # example input: input_image = "cat.jpg"
44
  # defining a function to generate caption using a image caption Gradio demo hosted on Spaces
 
77
  res = "\n".join([f"{i}.{ res[i-1]}" for i in range(1,len(res)+1)])
78
  return "Following list has the top three news items for the given search query : \n" + res
79
 
80
+
81
+ # example inputs: prompt = "I am bored what can I do?"
82
+ # defining a function to get an activity basee on activity type
83
+ # Activity type - education, recreational, social, DIY, charity, cooking, relaxation, music, and busywork.
84
+ def bored_api(activity_type) -> str:
85
+ """
86
+ Get a random activity to do based on the activity type.
87
+ """
88
+ activity_type_list = ["education", "recreational", "social", "diy", "charity", "cooking", "relaxation", "music", "busywork"]
89
+ activity_type = activity_type.lower()
90
+ if activity_type not in activity_type_list:
91
+ activity_type = random.choice(activity_type_list)
92
+
93
+ api_url = "https://www.boredapi.com/api/activity/?type=" + activity_type
94
+ response = requests.get(
95
+ api_url
96
+ )
97
+ return response.json()['activity']
98
+
99
+