parent
ccfa61fdf1
commit
3bc51e4046
@ -0,0 +1,2 @@
|
|||||||
|
OPENAI_API_KEY="YOUR_API_KEY"
|
||||||
|
DALLE_COOKIE="YOUR_COOKIE"
|
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 pliny
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
@ -0,0 +1,71 @@
|
|||||||
|
MythGen: A Dynamic New Art Form
|
||||||
|
Overview
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
MythGen is an Iterative Multimedia Generator that allows users to create their own comic stories based on textual prompts. The system integrates state-of-the-art language and image models to provide a seamless and creative experience.
|
||||||
|
Features
|
||||||
|
|
||||||
|
Initial Prompting: Kick-start your story with an initial text prompt.
|
||||||
|
Artistic Style Suffix: Maintain a consistent artistic style throughout your comic.
|
||||||
|
Image Generation: Generate captivating comic panels based on textual captions.
|
||||||
|
Caption Generation: Produce engaging captions for each comic panel.
|
||||||
|
Interactive Story Building: Select your favorite panels and captions to build your story iteratively.
|
||||||
|
Storyboard: View the sequence of your selected panels and their associated captions.
|
||||||
|
State Management: Keep track of the current state of your comic generation process.
|
||||||
|
User-Friendly Interface: Easy-to-use interface built on Gradio.
|
||||||
|
|
||||||
|
Prerequisites
|
||||||
|
OpenAI API Key
|
||||||
|
|
||||||
|
You will need an OpenAI API key to access GPT-3 for generating captions. Follow these steps to obtain one:
|
||||||
|
|
||||||
|
Visit OpenAI's Developer Dashboard.
|
||||||
|
Sign up for an API key and follow the verification process.
|
||||||
|
Once verified, you will be provided with an API key.
|
||||||
|
|
||||||
|
Bing Image Creator Cookie
|
||||||
|
|
||||||
|
You should obtain your cookie to run this program. Follow these steps to obtain your cookie:
|
||||||
|
|
||||||
|
Go to Bing Image Creator in your browser and log in to your account.
|
||||||
|
Press Ctrl+Shift+J to open developer tools.
|
||||||
|
Navigate to the Application section.
|
||||||
|
Click on the Cookies section.
|
||||||
|
Find the variable _U and copy its value.
|
||||||
|
|
||||||
|
How to Use
|
||||||
|
|
||||||
|
Initial Prompt: Start by inputting your initial comic concept.
|
||||||
|
Select a Panel: Choose your favorite panel and caption from the generated options.
|
||||||
|
Iterate: Use the "Next Part" button to generate the next part of your comic based on your latest selection.
|
||||||
|
View Storyboard: See your selected comic panels and captions in a storyboard for a comprehensive view of your comic.
|
||||||
|
Finalize: Continue this process until you've created your full comic story.
|
||||||
|
|
||||||
|
Installation
|
||||||
|
|
||||||
|
bash
|
||||||
|
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
Running MythGen
|
||||||
|
|
||||||
|
bash
|
||||||
|
|
||||||
|
python main.py
|
||||||
|
|
||||||
|
This will launch the Gradio interface where you can interact with MythGen.
|
||||||
|
Dependencies
|
||||||
|
|
||||||
|
Python 3.x
|
||||||
|
Gradio
|
||||||
|
OpenAI's GPT-3
|
||||||
|
DALL-E
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
|
||||||
|
We welcome contributions! Please read the CONTRIBUTING.md for guidelines on how to contribute to this project.
|
||||||
|
License
|
||||||
|
|
||||||
|
This project is licensed under the MIT License. See LICENSE.md for details.
|
@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "cookie1",
|
||||||
|
"value": "1lEXeWRSIPUsQ0S3tdAc3v7BexGK2qBlzsXz8j52w_HNBoOsegjiwRySQHmfoWduHVUxSXo6cETPP2qNrYWAz6k7wn43WGO9i7ll9_Wl7M6HA2c9twbKByfAtAB5fr26wPawQ6y1GCdakD_Kr4xdD20fvkytnmOmZu7Ktnb9mUVE605AAbJcIA9SOlRN5410ZPOnZA1cIzr4WtAFWNfQKPG6Sxk_zO5zvXQfYTyMNmOI"
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,85 @@
|
|||||||
|
import openai
|
||||||
|
import os
|
||||||
|
import dotenv
|
||||||
|
import logging
|
||||||
|
import gradio as gr
|
||||||
|
from dalle3 import Dalle
|
||||||
|
from bing_chat import BingChat
|
||||||
|
|
||||||
|
# from swarms.models.bingchat import BingChat
|
||||||
|
|
||||||
|
dotenv.load_dotenv(".env")
|
||||||
|
|
||||||
|
# Initialize the EdgeGPTModel
|
||||||
|
openai_api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
model = BingChat(cookie_path = "./cookies.json")
|
||||||
|
cookie = os.environ.get("BING_COOKIE")
|
||||||
|
auth = os.environ.get("AUTH_COOKIE")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
response = model("Generate")
|
||||||
|
|
||||||
|
# Initialize DALLE3 API
|
||||||
|
cookie = os.getenv("DALLE_COOKIE")
|
||||||
|
dalle = Dalle(cookie)
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
accumulated_story = ""
|
||||||
|
latest_caption = ""
|
||||||
|
standard_suffix = ""
|
||||||
|
storyboard = []
|
||||||
|
|
||||||
|
def generate_images_with_dalle(caption):
|
||||||
|
model.create_img(auth_cookie=cookie,auth_cookie_SRCHHPGUSR=auth,prompt=caption)
|
||||||
|
urls = dalle.get_urls()
|
||||||
|
return urls
|
||||||
|
|
||||||
|
def generate_single_caption(text):
|
||||||
|
prompt = f"A comic about {text}."
|
||||||
|
response = model(prompt)
|
||||||
|
return response
|
||||||
|
|
||||||
|
def interpret_text_with_gpt(text, suffix):
|
||||||
|
return generate_single_caption(f"{text} {suffix}")
|
||||||
|
|
||||||
|
def create_standard_suffix(original_prompt):
|
||||||
|
return f"In the style of {original_prompt}"
|
||||||
|
|
||||||
|
def gradio_interface(text=None, next_button_clicked=False):
|
||||||
|
global accumulated_story, latest_caption, standard_suffix, storyboard
|
||||||
|
|
||||||
|
if not standard_suffix:
|
||||||
|
standard_suffix = create_standard_suffix(text)
|
||||||
|
|
||||||
|
if next_button_clicked:
|
||||||
|
new_caption = interpret_text_with_gpt(latest_caption, standard_suffix)
|
||||||
|
new_urls = generate_images_with_dalle(new_caption)
|
||||||
|
latest_caption = new_caption
|
||||||
|
storyboard.append((new_urls, new_caption))
|
||||||
|
|
||||||
|
elif text:
|
||||||
|
caption = interpret_text_with_gpt(text, standard_suffix)
|
||||||
|
comic_panel_urls = generate_images_with_dalle(caption)
|
||||||
|
latest_caption = caption
|
||||||
|
storyboard.append((comic_panel_urls, caption))
|
||||||
|
|
||||||
|
storyboard_html = ""
|
||||||
|
for urls, cap in storyboard:
|
||||||
|
for url in urls:
|
||||||
|
storyboard_html += f'<img src="{url}" alt="{cap}" width="300"/><br>{cap}<br>'
|
||||||
|
|
||||||
|
return storyboard_html
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
iface = gr.Interface(
|
||||||
|
fn=gradio_interface,
|
||||||
|
inputs=[
|
||||||
|
gr.inputs.Textbox(default="Type your story concept here", optional=True, label="Story Concept"),
|
||||||
|
gr.inputs.Checkbox(label="Generate Next Part")
|
||||||
|
],
|
||||||
|
outputs=[gr.outputs.HTML()],
|
||||||
|
live=False # Submit button will appear
|
||||||
|
)
|
||||||
|
iface.launch()
|
@ -0,0 +1,62 @@
|
|||||||
|
from flask import Flask, request, jsonify
|
||||||
|
import openai
|
||||||
|
import logging
|
||||||
|
from dalle3 import Dalle
|
||||||
|
import os
|
||||||
|
import gradio as gr
|
||||||
|
import requests
|
||||||
|
from PIL import Image
|
||||||
|
from io import BytesIO
|
||||||
|
import dotenv
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
dotenv.load_dotenv(".env")
|
||||||
|
|
||||||
|
# Initialize OpenAI API, INPUT YOUR OWN OPENAI KEY
|
||||||
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
|
# Initialize DALLE3 API, INPUT YOUR OWN COOKIE
|
||||||
|
cookie = os.getenv("DALLE_COOKIE")
|
||||||
|
dalle = Dalle(cookie)
|
||||||
|
|
||||||
|
|
||||||
|
def interpret_text_with_gpt(text):
|
||||||
|
model_engine = "text-davinci-002"
|
||||||
|
panel_instructions = "Create a comic panel where"
|
||||||
|
refined_prompt = f"{panel_instructions} {text}"
|
||||||
|
|
||||||
|
response = openai.Completion.create(
|
||||||
|
engine=model_engine,
|
||||||
|
prompt=refined_prompt,
|
||||||
|
max_tokens=100
|
||||||
|
)
|
||||||
|
|
||||||
|
final_prompt = response.choices[0].text.strip()
|
||||||
|
return final_prompt
|
||||||
|
|
||||||
|
def generate_images_with_dalle(refined_prompt):
|
||||||
|
dalle.create(refined_prompt)
|
||||||
|
urls = dalle.get_urls()
|
||||||
|
return urls
|
||||||
|
|
||||||
|
def gradio_interface(text):
|
||||||
|
refined_prompt = interpret_text_with_gpt(text)
|
||||||
|
comic_panel_urls = generate_images_with_dalle(refined_prompt)
|
||||||
|
|
||||||
|
output = []
|
||||||
|
for i, url in enumerate(comic_panel_urls):
|
||||||
|
response = requests.get(url)
|
||||||
|
img = Image.open(BytesIO(response.content))
|
||||||
|
caption = f"Caption for panel {i+1}"
|
||||||
|
output.append((img, caption))
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
iface = gr.Interface(
|
||||||
|
fn=gradio_interface,
|
||||||
|
inputs=["text"],
|
||||||
|
outputs=[gr.outputs.Image(type="pil", label="Comic Panels"), "text"]
|
||||||
|
)
|
||||||
|
|
||||||
|
iface.launch()
|
@ -0,0 +1,8 @@
|
|||||||
|
dalle3==0.0.7
|
||||||
|
Flask==2.3.2
|
||||||
|
gradio==3.48.0
|
||||||
|
openai==0.28.1
|
||||||
|
Pillow==10.1.0
|
||||||
|
python-dotenv==1.0.0
|
||||||
|
Requests==2.31.0
|
||||||
|
swarms==1.8.2
|
Loading…
Reference in new issue