How to convert RASA base Text bot to Rasa base Voice Bot - rasa-nlu

I already inserted the value for the RASA NLU using text format but I want insert that value using voice command. I already create google voice to text file to get the text out put. But I didn't understand how to move that text value into my Rasa NLU. I am using Rasa Open Source.

It's difficult to understand what exactly you're doing without the code. But since you say that you get the text output, you can use it as a message sent to rasa Agent:
from rasa.core.agent import Agent
from rasa.utils.endpoints import EndpointConfig
async def chat(message):
agent = Agent.load("/path/to/your/model")
respond = await agent.handle_text(message)
return respond
asyncio.run(chat("hi"))

Related

Ruby - How download to my computer the photo sent by the user to the telegram bot?

I am using Ruby for my telegram bot. People send some information to bot, and some times it is photo. I Need to save this photo to my computer in directory with Ruby file and then send this photo another people if he or she is needed of it.
So, How do I download a photo that was sent to my Telegram bot? I know about getFile from official site of Telegram and about this question How do I download a file or photo that was sent to my Telegram bot? but i don't understand how to use it with Ruby, because i'm start ruby only 5 months ago.
I try to wrote different code, but all doesn't work...
bot.messages_handler(content_types=['photo'])
bot.send_message(message.chat_id,bot.get_file_url(message.photo[0].file_id))
I'm hope for your help.
UPDATE!
So, now after codding and analisis all information and answer I have code which can find 'file_id' of photo from message of user and use this 'file_id' for sending this photo to another users.
if message.photo
info_about_phot = message.photo.to_s #Hash all info about photo to string
for i in ((info_about_phot.index('#file_id="')+10)..
(info_about_phot.index('", #file_unique_id=')-1)) #find all simbols of 'file_id' inside info about photo
info_about_phot = info_about_phot + message.photo.to_s[i] #mabe 'file_id from all simbols'
end
end
bot.api.send_photo(chat_id: message.from.id, photo: info_about_phot) #send message with only photo
may be it is not so clear as variant of #mechnicov but it works perfect and help me with my problem. But if some body can write better code - i will say "Thanks!!!".
You didn't specify used gem
Just as example using telegram-bot-ruby
You can pass photo file_id from message to getFile method and get file information, that has file_path attribute
photo_url = bot.api.get_file(message.photo.last.file_id).file_path
It is photo URL. After that you can download file different ways with Ruby, for example
require "open-uri"
io = URI.open(photo_url)
File.open(path_to_save, 'w') { |f| f.write(io.read) }

How do I make it so that ctx is not of type 'interaction' (nextcord slash commands)?

I'm trying to create a music bot using nextcord slash commands and interactions. The command isn't fully finished yet, as I am having trouble getting it to even join the voice channel. I don't exactly know how interactions work yet but I'm assuming it's a similar concept as ctx. Below is my music.py cog:
import nextcord
from nextcord.ext import commands
from nextcord import Interaction
class Music(commands.Cog):
def __init__(self, client):
self.client = client
guild_ids = ["Guild Ids Go Here"]
#slash commands go under here
#nextcord.slash_command(name="play", description="plays music in vc", guild_ids = guild_ids)
async def play(self, interaction : Interaction, query: str):
channel = interaction.author.voice.channel #ERROR IS HERE
try:
await channel.connect()
await interaction.response.send_message("The bot has joined vc.")
except:
await interaction.response.send_message("Failed to find voice channel.")
def setup(client):
client.add_cog(Music(client))
I'm getting an error that says "'Interaction' object has no attribute 'author'. It occurs on line 15 in 'play' when it says 'channel = interaction.author.voice.channel'. I think this means that this isn't the right way to go about getting the author's voice channel. If this is the case, is there a better, working method?
In nextcord interaction, message author is interaction.user,
channel is interaction.channel.
You also can send interaction message by interaction.send instead
of interaction.response.send_message. It's much shorter and easier
to read.
If you want to send a normal message without using interaction, try
interaction.channel.send. It's similar to ctx.channel.send in application command

Attempting to read and download Outlook emails in jupyter notebook using win32

Two-fold issue: 1) Trying to download attachments from Outlook emails using win32 in Jupyter Notebook 2) I get notifications of different lessons and resources by phone. Then I usually, send the URL to the resource to my email to organize later on. Is there a way to use Jupyter Notebook to grab these emails and store them in an excel file? Here is the lesson I am trying to follow currently: https://towardsdatascience.com/automatic-download-email-attachment-with-python-4aa59bc66c25 . And here is my code:
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.items
message = message.GetFirst()
attachments = message.Attachments
attachment = attachments.Item(1)
attachment_name = str(attachment).lower() attachment.SaveAsFile(path + '\\' + atttachment_name)
exit
You never check that a message has attachments (message.Attachments.Count > 0) and you assume that you get a particular message from the Inbox: can either get the currently selected message (Application.ActiveExplorer.Selection collection) or you need to search for the particular message using Items.Find/FindNext or Items.Restrict. Items.GetLast will give some undetermined item.
Thirdly, the line message = message.GetFirst() was probably meant to be message = messages.GetFirst(). Still won't work, but at least it won't blow up because message variable is uninitialized.

I am trying to make a Telegram Bot. But getting error, don't know how to get rid of it

thats a simple code and Cmd output line
bot name - #ting_ting_bot
Ok, instead of telebot.Telebot use telebot.TeleBot. Note that B in TeleBot.
In the docs of pyTelegramBotApi's docs it is provided:
import telebot
bot = telebot.TeleBot("TOKEN", parse_mode=None) # You can set parse_mode by default. HTML or MARKDOWN

How to use Ruby to send image to a deployed Sagemaker endpoint running a TensorFlow/Keras CNN?

I have trained a CNN using Tensorflow/Keras and successfully deployed it to Sagemaker using the saved_model format. It answers pings and the dashboard shows it is running.
I now need to be able to send it images and get back inferences. I have already successfully deployed an ANN to Sagemaker and gotten predictions back, so most of the "plumbing" is already working.
The Ruby performing the request is as follows:
def predict
sagemaker = Aws::SageMakerRuntime::Client.new(
access_key_id: Settings.sagemaker_key_id,
secret_access_key: Settings.sagemaker_secret,
region: Settings.sagemaker_aws_region
)
response = sagemaker.invoke_endpoint(endpoint_name: Settings.sagemaker_endpoint_name,
content_type: 'application/x-image',
body: File.open('developer/ai/caox_test_128.jpg', 'rb'))
return response[:body].string
end
(For now, I simply hardcoded a known file for testing.)
When I fire this, I get back this error: Aws::SageMakerRuntime::Errors::ModelError: Received client error (400) from model with message "{ "error": "JSON Parse error: Invalid value. at offset: 0" }"
It's almost as if the model is expecting more in the body than just the image, but I can't tell what. AWS's documentation has an example for Python using boto:
import boto3
import json
endpoint = '<insert name of your endpoint here>'
runtime = boto3.Session().client('sagemaker-runtime')
# Read image into memory
with open(image, 'rb') as f:
payload = f.read()
# Send image via InvokeEndpoint API
response = runtime.invoke_endpoint(EndpointName=endpoint, ContentType='application/x-image', Body=payload)
# Unpack response
result = json.loads(response['Body'].read().decode())
As far as I can tell, they are simply opening a file and sending it directly to sagemaker with no additional pre-processing. And, insofar as I can tell, I'm doing exactly what they are doing in Ruby, just using 'aws-sdk'.
I've looked through Amazon's documentation, and for examples on Google, but there is scant mention of doing anything special before sending the file, so I'm scratching my head.
What else do I need to consider when sending a file to a Sagemaker endpoint running a TensorFlow/Keras CNN to get it to respond with a prediction?

Resources