parent
8d41ad1aa8
commit
707a9b5a32
@ -1,4 +1,4 @@
|
|||||||
discord.py==2.3.2
|
discord.py==2.3.2
|
||||||
python-dotenv==0.21.1
|
python-dotenv==1.0.0
|
||||||
PyYAML==6.0
|
PyYAML==6.0.1
|
||||||
EdgeGPT==0.13.2
|
bing-chat==1.9.3
|
||||||
|
@ -1,75 +0,0 @@
|
|||||||
import openai
|
|
||||||
import os
|
|
||||||
import dotenv
|
|
||||||
import logging
|
|
||||||
import gradio as gr
|
|
||||||
from BingImageCreator import ImageGen
|
|
||||||
from swarms.models.bing_chat import BingChat
|
|
||||||
|
|
||||||
# from swarms.models.bingchat import BingChat
|
|
||||||
dotenv.load_dotenv(".env")
|
|
||||||
|
|
||||||
# Initialize the EdgeGPTModel
|
|
||||||
model = BingChat()
|
|
||||||
|
|
||||||
response = model("Generate")
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
|
|
||||||
accumulated_story = ""
|
|
||||||
latest_caption = ""
|
|
||||||
standard_suffix = ""
|
|
||||||
storyboard = []
|
|
||||||
|
|
||||||
def generate_images_with_bingchat(caption):
|
|
||||||
img_path = model.create_img(caption)
|
|
||||||
img_urls = model.images(caption)
|
|
||||||
return img_urls
|
|
||||||
|
|
||||||
def generate_single_caption(text):
|
|
||||||
prompt = f"A comic about {text}."
|
|
||||||
response = model(text)
|
|
||||||
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 = generate_single_caption(latest_caption + " " + standard_suffix)
|
|
||||||
new_urls = generate_images_with_bingchat(new_caption)
|
|
||||||
latest_caption = new_caption
|
|
||||||
storyboard.append((new_urls, new_caption))
|
|
||||||
|
|
||||||
elif text:
|
|
||||||
caption = generate_single_caption(text + " " + standard_suffix)
|
|
||||||
comic_panel_urls = generate_images_with_bingchat(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()
|
|
@ -1,135 +1,77 @@
|
|||||||
|
import openai
|
||||||
import os
|
import os
|
||||||
import discord
|
|
||||||
from discord.ext import commands
|
|
||||||
import interpreter
|
|
||||||
import dotenv
|
import dotenv
|
||||||
import whisper
|
import logging
|
||||||
|
import gradio as gr
|
||||||
|
from BingImageCreator import ImageGen
|
||||||
|
from swarms.models.bing_chat import BingChat
|
||||||
|
|
||||||
|
# from swarms.models.bingchat import BingChat
|
||||||
dotenv.load_dotenv(".env")
|
dotenv.load_dotenv(".env")
|
||||||
|
|
||||||
bot_id = os.getenv("BOT_ID")
|
# Initialize the EdgeGPTModel
|
||||||
bot_token = os.getenv("DISCORD_TOKEN")
|
model = BingChat()
|
||||||
|
|
||||||
interpreter.api_key = os.getenv("OPENAI_API_KEY")
|
response = model("Generate")
|
||||||
# interpreter.api_base = os.getenv("API_BASE")
|
|
||||||
# interpreter.auto_run = True
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
accumulated_story = ""
|
||||||
def split_text(text, chunk_size=1500):
|
latest_caption = ""
|
||||||
#########################################################################
|
standard_suffix = ""
|
||||||
return [text[i : i + chunk_size] for i in range(0, len(text), chunk_size)]
|
storyboard = []
|
||||||
|
|
||||||
|
caption = "Create comic about opensourcerer a robot wizard"
|
||||||
# discord initial
|
|
||||||
intents = discord.Intents.all()
|
def generate_images_with_bingchat(caption):
|
||||||
intents.message_content = True
|
img_path = model.create_img(caption)
|
||||||
client = commands.Bot(command_prefix="$", intents=intents)
|
img_urls = model.images(caption)
|
||||||
|
return img_urls
|
||||||
message_chunks = []
|
|
||||||
send_image = False
|
def generate_single_caption(text):
|
||||||
|
prompt = f"A comic about {text}."
|
||||||
model = whisper.load_model("base")
|
response = model(text)
|
||||||
|
return response
|
||||||
|
|
||||||
def transcribe(audio):
|
def interpret_text_with_gpt(text, suffix):
|
||||||
# load audio and pad/trim it to fit 30 seconds
|
return generate_single_caption(f"{text} {suffix}")
|
||||||
audio = whisper.load_audio(audio)
|
|
||||||
audio = whisper.pad_or_trim(audio)
|
def create_standard_suffix(original_prompt):
|
||||||
|
return f"In the style of {original_prompt}"
|
||||||
# make log-Mel spectrogram and move to the same device as the model
|
|
||||||
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
def gradio_interface(text=None, next_button_clicked=False):
|
||||||
|
global accumulated_story, latest_caption, standard_suffix, storyboard
|
||||||
# detect the spoken language
|
|
||||||
_, probs = model.detect_language(mel)
|
if not standard_suffix:
|
||||||
|
standard_suffix = create_standard_suffix(text)
|
||||||
# decode the audio
|
|
||||||
options = whisper.DecodingOptions()
|
if next_button_clicked:
|
||||||
result = whisper.decode(model, mel, options)
|
new_caption = generate_single_caption(latest_caption + " " + standard_suffix)
|
||||||
return result.text
|
new_urls = generate_images_with_bingchat(new_caption)
|
||||||
|
latest_caption = new_caption
|
||||||
|
storyboard.append((new_urls, new_caption))
|
||||||
@client.event
|
|
||||||
async def on_message(message):
|
elif text:
|
||||||
await client.process_commands(message)
|
caption = generate_single_caption(text + " " + standard_suffix)
|
||||||
bot_mention = f"<@{bot_id}>"
|
comic_panel_urls = generate_images_with_bingchat(caption)
|
||||||
# if ("<@1158923910855798804>" in message.content) or (message.author == client.user or message.content[0] == '$'):
|
latest_caption = caption
|
||||||
# return
|
storyboard.append((comic_panel_urls, caption))
|
||||||
response = []
|
|
||||||
for chunk in interpreter.chat(message.content, display=False, stream=False):
|
storyboard_html = ""
|
||||||
# await message.channel.send(chunk)
|
for urls, cap in storyboard:
|
||||||
if "message" in chunk:
|
for url in urls:
|
||||||
response.append(chunk["message"])
|
storyboard_html += f'<img src="{url}" alt="{cap}" width="300"/><br>{cap}<br>'
|
||||||
last_response = response[-1]
|
|
||||||
|
return storyboard_html
|
||||||
max_message_length = 2000 # Discord's max message length is 2000 characters
|
|
||||||
# Splitting the message into chunks of 2000 characters
|
if __name__ == "__main__":
|
||||||
response_chunks = [
|
iface = gr.Interface(
|
||||||
last_response[i : i + max_message_length]
|
fn=gradio_interface,
|
||||||
for i in range(0, len(last_response), max_message_length)
|
inputs=[
|
||||||
]
|
gr.inputs.Textbox(default="Type your story concept here", optional=True, label="Story Concept"),
|
||||||
# Sending each chunk as a separate message
|
gr.inputs.Checkbox(label="Generate Next Part")
|
||||||
for chunk in response_chunks:
|
],
|
||||||
await message.channel.send(chunk)
|
outputs=[gr.outputs.HTML()],
|
||||||
|
live=False # Submit button will appear
|
||||||
|
)
|
||||||
@client.command()
|
iface.launch()
|
||||||
async def join(ctx):
|
|
||||||
if ctx.author.voice:
|
|
||||||
channel = ctx.message.author.voice.channel
|
|
||||||
print("joining..")
|
|
||||||
await channel.connect()
|
|
||||||
print("joined.")
|
|
||||||
else:
|
|
||||||
print("not in a voice channel!")
|
|
||||||
|
|
||||||
|
|
||||||
@client.command()
|
|
||||||
async def leave(ctx):
|
|
||||||
if ctx.voice_client:
|
|
||||||
await ctx.voice_client.disconnect()
|
|
||||||
else:
|
|
||||||
print("not in a voice channel!")
|
|
||||||
|
|
||||||
|
|
||||||
@client.command()
|
|
||||||
async def listen(ctx):
|
|
||||||
if ctx.voice_client:
|
|
||||||
print("trying to listen..")
|
|
||||||
ctx.voice_client.start_recording(discord.sinks.WaveSink(), callback, ctx)
|
|
||||||
print("listening..")
|
|
||||||
else:
|
|
||||||
print("not in a voice channel!")
|
|
||||||
|
|
||||||
|
|
||||||
async def callback(sink: discord.sinks, ctx):
|
|
||||||
print("in callback..")
|
|
||||||
for user_id, audio in sink.audio_data.items():
|
|
||||||
if user_id == ctx.author.id:
|
|
||||||
print("saving audio..")
|
|
||||||
audio: discord.sinks.core.AudioData = audio
|
|
||||||
print(user_id)
|
|
||||||
filename = "audio.wav"
|
|
||||||
with open(filename, "wb") as f:
|
|
||||||
f.write(audio.file.getvalue())
|
|
||||||
print("audio saved.")
|
|
||||||
transcription = transcribe(filename)
|
|
||||||
print(transcription)
|
|
||||||
response = []
|
|
||||||
for chunk in interpreter.chat(transcription, display=False, stream=True):
|
|
||||||
# await message.channel.send(chunk)
|
|
||||||
if "message" in chunk:
|
|
||||||
response.append(chunk["message"])
|
|
||||||
await ctx.message.channel.send(" ".join(response))
|
|
||||||
|
|
||||||
|
|
||||||
@client.command()
|
|
||||||
async def stop(ctx):
|
|
||||||
ctx.voice_client.stop_recording()
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_ready():
|
|
||||||
print(f"We have logged in as {client.user}")
|
|
||||||
|
|
||||||
|
|
||||||
client.run(bot_token)
|
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue