From 037ff930b06ff0c67c19ed311c6c97eabb848ccf Mon Sep 17 00:00:00 2001
From: Sneha-S-D <133686184+Sneha-S-D@users.noreply.github.com>
Date: Mon, 15 Apr 2024 20:47:38 +0530
Subject: [PATCH] Spotify uAgents |Tech_Titans |PixAthon
Added README files
---
.../Agentverse/README.md | 3 +
.../Agentverse/agent1.py | 36 +++++++++
.../Local_agent/README.md | 49 ++++++++++++
.../Local_agent/communication.py | 77 +++++++++++++++++++
.../Spotify API with uAgents/README.md | 54 +++++++++++++
5 files changed, 219 insertions(+)
create mode 100644 integrations/Spotify API with uAgents/Agentverse/README.md
create mode 100644 integrations/Spotify API with uAgents/Agentverse/agent1.py
create mode 100644 integrations/Spotify API with uAgents/Local_agent/README.md
create mode 100644 integrations/Spotify API with uAgents/Local_agent/communication.py
create mode 100644 integrations/Spotify API with uAgents/README.md
diff --git a/integrations/Spotify API with uAgents/Agentverse/README.md b/integrations/Spotify API with uAgents/Agentverse/README.md
new file mode 100644
index 00000000..2ee6736a
--- /dev/null
+++ b/integrations/Spotify API with uAgents/Agentverse/README.md
@@ -0,0 +1,3 @@
+This file that is agent1 was online uAgent developed inside agentverse and is hosted there.This is a single bot which is integrated with Delta V under the services named singers.One can operate this agent by logging into Delta V.
+
+You can also follow the documentation.
\ No newline at end of file
diff --git a/integrations/Spotify API with uAgents/Agentverse/agent1.py b/integrations/Spotify API with uAgents/Agentverse/agent1.py
new file mode 100644
index 00000000..c7e69410
--- /dev/null
+++ b/integrations/Spotify API with uAgents/Agentverse/agent1.py
@@ -0,0 +1,36 @@
+from pydantic import Field
+from ai_engine import UAgentResponse, UAgentResponseType
+
+class Spotify(Model):
+ Singer: str =Field(description="Enter Singer")
+ genre: str=Field(description="Enter A Genre")
+
+
+
+Spotify_protocol = Protocol("Spotify")
+
+
+@Spotify_protocol.on_message(model=Spotify, replies={UAgentResponse})
+async def Search(ctx: Context, sender: str, msg: Spotify):
+
+
+ url = "https://spotify23.p.rapidapi.com/search/"
+ querystring = {"q":{msg.Singer},"type":{msg.genre},"offset":"0","limit":"10","numberOfTopResults":"5"}
+
+ headers = {
+ "X-RapidAPI-Key": "API KEY ",
+ "X-RapidAPI-Host": "spotify23.p.rapidapi.com"
+ }
+ response = requests.get(url, headers=headers, params=querystring)
+ file=response.json()
+
+ for album in file['albums']['items']:
+ album_name = album['data']['name']
+ album_artist = ', '.join(artist['profile']['name'] for artist in album['data']['artists']['items'])
+ album_year = album['data']['date']['year']
+ message = f"Album: {album_name}\nArtist(s): {album_artist}\nYear: {album_year}"
+ await ctx.send(
+ sender, UAgentResponse(message=message, type=UAgentResponseType.FINAL)
+ )
+ break
+agent.include(Spotify_protocol, publish_manifest=True)
\ No newline at end of file
diff --git a/integrations/Spotify API with uAgents/Local_agent/README.md b/integrations/Spotify API with uAgents/Local_agent/README.md
new file mode 100644
index 00000000..ccbf0db8
--- /dev/null
+++ b/integrations/Spotify API with uAgents/Local_agent/README.md
@@ -0,0 +1,49 @@
+
+## uAgents:AI Agent Framework
+ uAgents is a library developed by Fetch.ai that allows for creating autonomous AI agents in Python. Here there are two agents that communicatie with each other, one agent dispalys the menu and the other agent selects an option from the menu, then the first agent calls the API based on the search and dispalys the result.
+# π Features
+π€ Easy creation and management: Create any type of agent you can think of and put into code.
+π Connected: On startup, each agent automatically joins the fast growing network of uAgents by registering on the Almanac, a smart contract deployed on the Fetch.ai blockchain.
+π Secure: uAgent messages and wallets are cryptographically secured, so their identities and assets are protected.
+
+## β‘ Quickstart
+Installation
+Get started with uAgents by installing it for Python 3.9 to 3.12:
+
+[pip install uagents] (https://pypi.org/project/uagents/)
+
+Clone the repository to your system and run it on your terminal.
+Cloning a repository
+1]On GitHub.com, navigate to the main page of the repository.
+
+2]Above the list of files, click <> Code.
+
+3]Copy the URL for the repository.
+
+To clone the repository using HTTPS, under "HTTPS", click copy link .
+
+To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click SSH, then click copy link .
+
+To clone a repository using GitHub CLI, click GitHub CLI, then click copy link .
+
+4]Open Git Bash.
+
+5]Change the current working directory to the location where you want the cloned directory.
+
+6]Type git clone, and then paste the URL you copied earlier.
+
+(git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY)
+
+7]Press Enter to create your local clone.
+
+8]Then open the file named communication.py
+## Agents working:
+
+Here there are two agents sneha and sarvesh that are comunicating. agent sneha displays the menu and agent sarvesh now has to select and option and if the option is 1,agent sneha will ask for the name and genre of the artist and based on the input it will look for the top albums and displays the album name ,the artist name and the year of release on the terminal.
+After displaying it the agent again displays the menu and if the option is 2, the user has to enter the ID of the arist and then the details of the arist will be displayed on the terminal.
+
+
+After cloning the repo on your system , enter the API key where it is mentioned and then run the program on your terminal.
+
+You should see the results on your terminal.
+
diff --git a/integrations/Spotify API with uAgents/Local_agent/communication.py b/integrations/Spotify API with uAgents/Local_agent/communication.py
new file mode 100644
index 00000000..f7479966
--- /dev/null
+++ b/integrations/Spotify API with uAgents/Local_agent/communication.py
@@ -0,0 +1,77 @@
+import requests
+from prettyprinter import pprint
+from uagents import Agent, Bureau, Context, Model
+
+class Message(Model):
+ message: str
+
+sneha = Agent(name="sneha", seed="sneha recovery phrase")
+sarvesh = Agent(name="sarvesh", seed="sarvesh recovery phrase")
+
+@sneha.on_interval(period=3.0)
+async def send_message(ctx: Context):
+ await ctx.send(sarvesh.address, Message(message="Choose a genre: \n1] Search song,artist, album name \n2] For searching Artist by ID \n"))
+
+@sneha.on_message(model=Message)
+async def sneha_message_handler(ctx: Context, sender: str, msg: Message):
+ ctx.logger.info(f"Received message from {sender}: {msg.message}")
+ genre_choice = int(msg.message.split(": ")[1])
+ if genre_choice == 1:
+ url = "https://spotify23.p.rapidapi.com/search/"
+ name=input("name \n")
+ type=input("enter type / gener\n")
+ querystring = {"q":{name},"type":{type},"offset":"0","limit":"10","numberOfTopResults":"5"}
+
+ headers = {
+ "X-RapidAPI-Key": "API KEY",
+ "X-RapidAPI-Host": "spotify23.p.rapidapi.com"
+ }
+
+ response = requests.get(url, headers=headers, params=querystring)
+ file=response.json()
+
+ for album in file['albums']['items']:
+ album_name = album['data']['name']
+ album_artist = ', '.join(artist['profile']['name'] for artist in album['data']['artists']['items'])
+ album_year = album['data']['date']['year']
+ print(f"Album: {album_name}")
+ print(f"Artist(s): {album_artist}")
+ print(f"Year: {album_year}")
+ print()
+
+ #pprint(response.json())
+ await ctx.send(sarvesh.address, Message(message="\n\t\t*******List ends here!*******\n"))
+
+ elif genre_choice == 2:
+
+ url = "https://spotify23.p.rapidapi.com/artists/"
+
+ artist=input("Enter artist ID\n")
+ querystring = {"ids":{artist}}
+
+ headers = {
+ "X-RapidAPI-Key": "KEY",
+ "X-RapidAPI-Host": "spotify23.p.rapidapi.com"
+}
+
+ response = requests.get(url, headers=headers, params=querystring)
+ file=response.json()
+ for album in file['artists']:
+ name=album['name']
+ geners=album['genres']
+ artist=album['external_urls']
+ userli=album['uri']
+ print(f"\n {name}\n {geners}\n{userli}\n{artist}\n")
+
+
+@sarvesh.on_message(model=Message)
+async def sarvesh_message_handler(ctx: Context, sender: str, msg: Message):
+ ctx.logger.info(f"Received message from {sender}: {msg.message}")
+ genre_choice = int(input("Enter the number corresponding to the genre you choose: "))
+ await ctx.send(sneha.address, Message(message=f"Chosen genre: {genre_choice}"))
+
+bureau = Bureau()
+bureau.add(sneha)
+bureau.add(sarvesh)
+if __name__ == "__main__":
+ bureau.run()
diff --git a/integrations/Spotify API with uAgents/README.md b/integrations/Spotify API with uAgents/README.md
new file mode 100644
index 00000000..e2642eb7
--- /dev/null
+++ b/integrations/Spotify API with uAgents/README.md
@@ -0,0 +1,54 @@
+# Spotify API with uAgentsπ€π΅.
+
+Using Spotify API (Rapid API integration) For fetching spotify songs, artist, album and playlist details with use of Fetch.ai AI Agent tech.
+
+
+## Instructions to run the project ππ°.
+
+[1] Search for 'DeltaV agentverse ai' on your preferred web browser. or click [DeltaV](https://deltav.agentverse.ai/home)
+
+
+
+[2] If trying it for the first time go for signup option or you can continue with login option.
+
+[3] You will be guided to the Home page of DeltaV.
+
+
+
+![App Screenshot](https://fetch.ai/docs/_next/image?url=%2Fdocs%2F_next%2Fstatic%2Fmedia%2Fdeltav_chat_interface.aed32d95.png&w=3840&q=75)
+
+
+[4] Switch for Advanced Options and Choose 'Songs' from the Service groups dropdown.
+
+
+
+
+
+[5] After selecting Songs as Service groups, Press Start button on the search bar.
+
+[6]The uAgent will work on itself and now we will have to communicate with the agent as the coversation flows.
+
+## Agent 1: Spotify Agent ππ°
+The Spotify Agent continously fetches the top known playlist , song and album of the artist, fetches it from the
+The News Data Provider Agent continuously fetches top news articles from an external API and sends this data to other agents for processing and display.
+
+### Features:
+-User firendly application.
+- Most known song of the artist is displayed with.
+- Music choice depending on the mood.
+- Configurable API endpoint and data fetching interval.
+
+## Tech: π»π:
+-API service used [RapidAPI](https://rapidapi.com/hub). β
+-API used [SPOTIFY](https://rapidapi.com/Glavier/api/spotify23). :dependabot:
+-Agent by [Agent Verse](https://agentverse.ai/) by [Fetch ai](https://fetch.ai/).
+
+## Do try out this amazing tech:
+Follow the documentations of-
+[Fetch ai](https://fetch.ai/docs)
+[Agent Verse](https://fetch.ai/docs/guides/agentverse/creating-a-hosted-agent)
+Happy Coding π€π
+
+## Here is the video explanation of the project
+
+ Video (https://youtu.be/kKgl_2NaiK8?si=U7HoK5pCe8YDi24t)
\ No newline at end of file