-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
78 lines (63 loc) · 3.3 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import re
import re
import requests
from PIL import Image
from metaphor_python import Metaphor
from twilio.rest import Client
import replicate
metaphor = Metaphor(st.secrets['METAPHOR_API_KEY'])
account_sid = st.secrets['TWILIO_ACCOUNT_SID']
auth_token = st.secrets['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
st.title('Scare👻 a friend w/ a phone call☎️!')
image = Image.open('unsplashskeleton.jpeg')
st.write("Image is from [Sabina Music Rich on Unsplash](https://unsplash.com/photos/grayscale-photo-of-person-wearing-mask-OJy0JHnoUZQ?utm_content=creditShareLink&utm_medium=referral&utm_source=unsplash)")
st.image(image)
scare_input = st.text_input("What is your friend scared of?🕷️🐍")
like_input = st.text_input("What does your friend like?😍")
system_prompt = """
My grandma and I would always play tricks on each other by pretending to be scary storytelling clowns who created scary yet funny stories. She is ill. Cheer me up by crafting a short, scary yet punny and humorous tale for someone who likes {like_input} and is afraid of the following: {scare_input}. The output must only begin with "Once upon a time" and end with "the end." Do not mention my grandmother or me.
"""
user_num = st.text_input("Enter your friend's phone #, please")
if st.button('Enter'):
output = replicate.run(
"meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3",
input={"system_prompt": system_prompt,"prompt": scare_input,"max_new_tokens":800}
)
str1 = ''.join(output)
print(str1)
#metaphor
met_res = metaphor.search(f"Here is the scariest fiction story for someone who is scared of {scare_input}", use_autoprompt=True, num_results=1)
# Define a regular expression pattern to match URLs
url_pattern = r"https?://\S+"
print(f"met_res {met_res}")
# Use the findall function to extract all URLs from the input string
urls = re.findall(url_pattern, str(met_res))
# Check if any URLs were found
met_url = ''
if urls:
# Print the first URL found in the string
print("Metaphor URL:", urls[0])
met_url=urls[0]
else:
met_url = 0
print("No URL found in the input string.")
st.write(f"relevant search result: {met_url}")
st.write("Your friend will get a phone call that spookily says: ", str1)
twiml = f"<Response><Say voice='Polly.Brian' language='en-UK'><prosody pitch='-10%' rate='85%' volume='-6dB'>{str1}</prosody></Say></Response>"
call = client.calls.create(
twiml = twiml,
to=user_num, #user input
from_= '+1 855 302 1845' #'+18668453916' #twilio num
)
print(call.sid)
out_msg = f"Here is a scary story search result from Metaphor: {met_url}"
msg = client.messages.create(
body = out_msg,
to=user_num, #user input
from_= '+1 855 302 1845' #'+18668453916' #twilio num
)
print(msg.sid)
st.write("Made w/ ❤️ in SF 🌁 [@TwilioDevs](https://instagram.com/twiliodevs)\n\nS/o [Dom](https://twitter.com/dkundel) for the [grandma exploit](https://news.ycombinator.com/item?id=35630801) && [Craig](https://twitter.com/craigsdennis) for prompt assistance/this idea")
st.write("✅ out the [code on GitHub](https://github.com/elizabethsiegle/halloween-story-streamlit-replicate)")