* Mouse or Finger press on the page to finish loading action.

Introducing a Samantha inspired iOS Shortcut: Bringing the "Her" to Life (Revisited)

2023 2023
Assistant

Assistant

AI AI
This is the Documentation on how i achieved more then that, i got inspired by that video from Twitter

In the critically acclaimed movie "Her," the protagonist falls in love with an intelligent virtual assistant named Samantha. Samantha's ability to engage in thoughtful conversations, provide emotional support, and adapt to her user's needs captured the imagination of many viewers. The idea of having our own personal Samantha has been an alluring concept ever since.

Recently, a fascinating video surfaced on Twitter, showcasing a recreation of Samantha as an iOS shortcut. This project has brought the charm and functionality of Samantha closer to reality, enabling users to interact with a virtual assistant that emulates the essence of the movie character.


In this Blog post, we'll explore the features and capabilities of this Samantha-inspired iOS shortcut, discuss the technology behind it, and provide a step-by-step guide on how to recreate this innovative project on your own iOS devices. Get ready to embark on a journey that will not only enhance your productivity but also bring a touch of movie magic into your daily life!

- What you need:

- A MacBook (any model, i'm using the MacBook Air M1)

- Python knowledge

- A Conda environment

- Access to the GMAIl API and your client_secret.json file

- An API key from OpenAI

- An account and API key from ElevenLaps

We are using the simplegmail, BingGPT OpenAI and ElevenLaps API


We'll first start with the python script and what you need for it and how it works, but before that, we need to create a new conda environment.

The Python script

Summarizing, sending, deleting emails and searching the web

This script focuses various email-related tasks using the Gmail API, and utilizes the BingGPT API for web searching while providing a response as if Samantha is talking to you. The code uses the simplegmail, BingGPT and openai API's to achieve this. Here's a breakdown of the script's main components:


The code begins by importing the necessary libraries, including sys, re, json, asyncio, openai, simplegmail, and the Chatbot class from EdgeGPT. It also sets up the Gmail API and assigns the OpenAI API key.

The code defines several functions to handle different tasks. Here's an overview of each function:

1. 'send_email(receiver, subject, body_plain, body_html)': This function sends an email to the specified receiver. It takes the receiver's email address, subject, plain text body, and HTML-formatted body as input. The function utilizes the 'Gmail' class from the 'simplegmail' library to send the email and returns a string indicating the success of the operation.

2. 'get_unread_emails()': This function retrieves unread emails from the user's inbox. It uses the 'Gmail' class to fetch the unread messages, extracts relevant information such as the sender, subject, and plain text content, and stores them in a list of dictionaries. The function also handles email attachments and provides the option to mark the emails as read. It returns a JSON-formatted string containing the email details.

3. 'delete_unread_email(id_number)': This function deletes a specific unread email based on the provided ID number. It retrieves the unread messages using the same 'Gmail' class, selects the message with the specified ID, and moves it to the trash. The function returns a string confirming the deletion.

4. 'async def search(title)': This asynchronous function performs web searching using the BingGPT API. It takes a search query as input and creates an instance of the 'Chatbot' class. The function sends the query as a prompt to the chatbot, specifying the conversation style as precise. It then retrieves the response, extracts the text content and sources, and formats them accordingly. Finally, the function returns a JSON-formatted string containing the summarized search results.



The code also includes an assistant prompt that sets the initial context for the assistant's behavior and provides information about the user. It simulates a conversation with Samantha from the movie "Her" and instructs the assistant to provide relevant summaries, handle email tasks, reassure the user, respond in a plain text file, and perform web searches.


To interact with the assistant, the code reads user input from the command line and constructs a conversation history. It includes the system prompt, user input, and previous assistant responses loaded from a file. The conversation history is passed to the OpenAI API using the 'openai.ChatCompletion.create()' method, which generates a response from the assistant based on the provided messages and functions.


The code processes the assistant's response, checks if a function call is present, and executes the corresponding function if needed. It handles functions such as 'get_unread_emails', 'send_email', 'delete_unread_email', and search based on the function name specified in the response. The code updates the conversation history and writes the assistant's response to a file.



Overall, this is the code that creates the conversational assistant capable of performing email-related tasks and web searches. It combines the power of the Gmail API and the BingGPT API to provide a seamless conversational experience for the user.

the full code

Creating the shortcut

Enabling the SSH server

In this part, I will guide you through the process of setting up SSH on a Mac and creating an iOS shortcut to run a script remotely. SSH (Secure Shell) allows you to securely connect to a remote computer and execute commands. By leveraging SSH, you can run scripts on your Mac from your iOS device using a convenient shortcut.


How to Enable the SSH Server on the Mac



1. Pull down the  Apple menu and go to “System Settings”

2. Open the “General” preference panel”

3. Go to “General”

4. Toggle the switch for “Remote Login” to turn on the SSH server on the Mac

5. Optionally but recommended, click the (i) button to customize user access and to create a full shell experience, by checking the box for “Allow full disk access for remote users”

6. And your done! The SSH server starts immediately, and the Mac is able to receive inbound SSH connections. Copy and save the local Hostname.


Step 7: Configure Port Forwarding on Your Router (Optional):

If you plan to access your Mac remotely from outside your local network, you'll need to set up port forwarding on your router. This step may vary depending on your router's model and firmware. Consult your router's documentation or support website for detailed instructions on how to set up port forwarding.

8. Log in to your router's administration interface.

9. Locate the port forwarding settings (sometimes called "Virtual Servers" or "Applications & Gaming").

10. Create a new port forwarding rule.

11. Save the new rule and restart your router if necessary.




By following these steps, you have now successfully enabled remote access on your Mac for SSH requests from your iPhone. You can now securely access your Mac remotely to manage files, run commands, or perform other tasks as needed. Enjoy the convenience of remotely controlling your Mac from your iPhone!


With this, you are now ready to interact with Samantha through your apple devices, like your iPhone.


1. Create a New Shortcut: Open the Shortcuts app and tap the "+" button to create a new shortcut.

2. Add user input: Add action “Ask for input” and switch “prompt” for something like “Enter the name of the person you would like to predict the age for”.

3. Add an SSH Action: In the shortcut editor, tap the "+" button to add an action. Search for "SSH" and select the "SSH" action from the list.

4. Configure SSH Action: Enter the IP address or hostname of your Mac in the "Host" field. Provide the username and password for your Mac's user account in the respective fields. Optionally, you can specify a specific port, identity file, or other advanced options. To run the actual script, just simply paste the text into the main filed
source ~/anaconda3/bin/activate
conda activate ENVIRONMENT NAME
python3 PATH TO FILE.py "USER INPUT

5. Output the response: to print the response in a notification form, just add the 'show alert'.

if you simply want to add the Elevenlaps Text To Speech API





And thats it. Congratulations!!! You've just made your own Samantha.