Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1/clip work #8

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/image_path_resized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/integrations/diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def image_to_image(diffusion_model_predictor, image_url: str, prompt: str, user
return decode_and_show(sdxl_response, filename)
except Exception as e:
# Handle general exceptions
print(f"Error generating image: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))

def download_profile_image(url, username):
Expand Down
31 changes: 19 additions & 12 deletions app/integrations/twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ async def stop_bot():
await bot.close()
bot = None

# def get_user_profile_url(client, username):
# users = client.fetch_users(names=[username])
# if users:
# user = users[0]
# return user.profile_image
# else:
# return None

class TwitchBot(commands.Bot):
def __init__(self, token, channels):
print(f"Initializing TwitchBot with channels {channels}")
Expand Down Expand Up @@ -79,15 +71,26 @@ async def llm_command(self, ctx):
await ctx.send(llm.help_text)
return

temp_addon = " return the result in under 500 characters as a response to a user in chat"
prompt = " ".join(split[2:])+temp_addon # "explain my next step"
temp_addon = "Respond in less than 500 characters as a chatbot would: "
prompt = temp_addon+" ".join(split[2:]) # "explain my next step"
print(f"Received command: {ctx.message.content}") # !llm mistral explain my next step
print(f"Prompt: {prompt}") # explain my next step

response = llm.query(llm_type, prompt) # "mistral", "explain my next step"
answer = response.split(temp_addon)[-1]
answer = response.split(prompt)[-1]
print(f"Response: {answer}")

# Considering the length of username and additional characters in the message
max_length = 500 - len(ctx.author.name) - 4 # 4 for " @: "
if len(answer) > max_length:
answer = answer[:max_length] + ".."

await ctx.send(" @" + ctx.author.name+ ": " + answer)
# Splitting the answer into chunks of 500 characters
# chunks = [answer[i:i+500] for i in range(0, len(answer), 500)]

# for chunk in chunks:
# await ctx.send(" @" + ctx.author.name+ ": " + chunk)

@commands.command(name="diffuse")
async def diffuse_command(self, ctx):
Expand Down Expand Up @@ -125,7 +128,11 @@ async def welcome_command(self, ctx):
"image_url": profile_image_url,
"title": "welcome image"
}
diffusers.prompt_diffuser_image_to_image(prompt_map)
try:
diffusers.prompt_diffuser_image_to_image(prompt_map)
except Exception as e:
print(f"Error: {e}")
ctx.send(f"Error: {e}")

@commands.command(name="commands")
async def commands_command(self, ctx):
Expand Down
7 changes: 6 additions & 1 deletion app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ uvicorn
sagemaker
boto3
IPython
python-dotenv
python-dotenv
lanchain-experimental
pillow
open_clip_torch
torch
matplotlib