Spaces:
Runtime error
Runtime error
File size: 6,767 Bytes
2c872c4 0a3cbad 2c872c4 0a3cbad 723854e 2c872c4 fbbe460 2c872c4 fbbe460 2c872c4 fbbe460 2c872c4 fbbe460 2c872c4 9dd2eea 2c872c4 96c0a64 2c872c4 13a6a54 43881b2 2c872c4 43881b2 2c872c4 e335f64 2c872c4 b97f7fe 2c872c4 e335f64 2c872c4 13a6a54 2c872c4 e335f64 2c872c4 723854e 13a6a54 e335f64 13a6a54 e9448cb 2c872c4 13a6a54 |
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import gradio as gr
import os
import json
import requests
import openai
import re
#Streaming endpoint
API_URL = "https://api.openai.com/v1/chat/completions"
TWITTER_BEARER = os.getenv("TWITTER_BEARER")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
##### stable diffusion
stable_diffusion = gr.Blocks.load(name="spaces/runwayml/stable-diffusion-v1-5")
def get_images(username):
prompt_string = query(username)
regexed_prompt_string = re.sub(r'@\w+', '', prompt_string)
prompt_list = [element.split(". ")[1] for element in regexed_prompt_string.split(", ")]
prompt_list_prepend = [f"an photo of {item}, photorealistic, coherent, high quality, rendered in unreal engine" for item in prompt_list]
print(prompt_list_prepend)
image_dirs = []
for prompt in prompt_list_prepend:
image_dirs.append(stable_diffusion(prompt, fn_index=2))
sd_output = []
for image_dir in image_dirs:
found_first_image = False
for filename in os.listdir(image_dir):
if filename.endswith('.json'):
continue
elif not found_first_image:
sd_output.append(os.path.join(image_dir, filename))
found_first_image = True
return sd_output, prompt_string
with gr.Blocks(theme="gradio/soft") as demo:
gr.Markdown("# 🎁 Starter Pack Generator 🎁")
gr.Markdown("Enter a twitter username and this will return a starter pack for a person based on their latest tweets 🦜")
gr.Markdown("Each generation might take up to a minute, please be patient, grab a green tea 🍵")
gr.Markdown("This application uses Stable Diffusion space, so if you get `The queue is full!` please try again later, give the artist some break 🧑🎨")
with gr.Row():
with gr.Column():
input_text = gr.Textbox(label="Input user ID",
lines=4, elem_id="input-text")
with gr.Row():
enter_username = gr.Button("Submit")
with gr.Column(elem_id="generated-gallery"):
sd_output = gr.Gallery().style(grid=3, height="auto")
openai_output = gr.Textbox(lines=4)
enter_username.click(get_images,
inputs = [
input_text
],
outputs = [sd_output, openai_output]
)
#########
#### prompt creation
def openai_create(prompt):
openai.api_key=OPENAI_API_KEY
response = openai.Completion.create(
model="text-davinci-003",
max_tokens = 100,
prompt=prompt, stop="10.")
return response.choices[0].text
def query(username):
bearer_token = TWITTER_BEARER
headers = {"Authorization": "Bearer {}".format(bearer_token)}
url = f"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={username}&count={40}"
try:
response = requests.request("GET", url, headers = headers)
print(response)
twitter_stream = ""
for tweet in response.json():
twitter_stream += tweet["text"]
except Exception as e:
print(e)
result = ["Please make sure you are providing a correct, public twitter account"]
if twitter_stream:
twitter_stream = re.sub(r'@\w+', '', twitter_stream)
prompt_text=f"""You will be given a long twitter stream belonging to a specific profile.
I would like you to come up with a list of nine important concepts or items that user likes or is about them, and can be illustrated.
Ignore any mentions to other people.
Examples:
Twitter stream:
noughties Turkey was the coolest
listening to this set for flow today 🏞️
this meme isn't brought to you by my hugging face persona, that one is below
I often feel like what people really want vs what they say they want often mismatch. popular examples of this behavior these days, they want alexa to speak like generative models but they'd hate that if it happened.
today we eat börek & kurabiye
I feel like I will never ever love anything like I love mediterrenean 🌴🌊💙 I don't know if anyone else feels this way
I'm ranked 10th on github trending today 😭 https://github.com/trending/developers
paris is never cold, people are underdressed
my all time favorite books are Meditations by Marcus Aurelius & Discourses by Epictetus, makes your skin thicker and you more resilient to challenges of life
Concepts: 1. Turkish flag, 2. DJ set, 3. hugging face, 4. robot, 5. pastry, 6. mediterrenean, 7. github, 8. baguette bread, 9. meditations
Twitter stream:
Well im suck again, but imma stream some resident evil 4 if you wanna chill
I thought wearing a turtle neck and gold chain was a meme
Soon as I became old enough to wear "dad clothes" I dove right in. No hesitation. I've never been more comfortable in my life.
All the video and audio goes from gaming pc over the network to the stream pc. Skips all that annoying audio wiring. No problems yet!
The Silent Hill announcements are cool and all but the only things I've been able to rely on Konami to do in the past 10 years is aggressively claim music used in their videogames on YouTube, make pachinko machines, and cancel Silent Hill games.
Every video I make
THERE IS TOO MUCH TO DO IN ELDEN RING
Overall my move to Australia has been pretty great.
Went out for a Karaoke night with some friends but when it was my turn to sing.
Concepts: 1. resident evil zombies, 2. a man wearing a turtle neck and gold chain, 3. dad clothes, 4. pc setup, 5. silent hill game, 6. youtube, 7. elden ring, 8. australia, 9. karaoke set
Twitter stream:
Meet Sonny! Our brand new coffee mascot! He’s brewing up some fun.
This World Cup final is insane!!!
I'm going to be on The Late Late Show in Ireland again this Friday!
My next video will be my 5,000th upload
CAT GAME 🐈 https://youtube.com/watch?v=OaE_UPIfiAo
Happy Valentine’s Day ❤️ I hope you feel loved today, even if that love has to come from yourself. Treat yourself. Evelien surprised me 😊
Starting a Let’s Play channel with Tom Holland
I normally never do reviews but I couldn’t NOT talk about Dune! https://youtu.be/yh9Evgt6ZBg
@Spider-Man 2 Can’t wait!!
Concepts: 1. coffee 2. football 3. Ireland 4. video 5. cat 6. love 7. gaming 8. Dune 9. spider-man
Now, provide the list of 9 concepts for following twitter stream:
Twitter stream: {twitter_stream}
Concepts:
"""
result = openai_create(prompt=prompt_text)
print(result)
return result
#######
demo.queue().launch(debug=True) |