-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,009 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import requests | ||
import re | ||
|
||
|
||
class AnilistHandler: | ||
def __init__(self): | ||
self.url = 'https://graphql.anilist.co' | ||
|
||
def strip_html_tags(self, text): | ||
clean = re.compile('<.*?>') | ||
return re.sub(clean, '', text) | ||
|
||
def get_anime_description(self, name): | ||
query = ''' | ||
query ($name: String!) { | ||
Media(search: $name, type: ANIME) { | ||
description | ||
} | ||
} | ||
''' | ||
variables = {'name': name} | ||
response = requests.post(self.url, json={'query': query, 'variables': variables}) | ||
if response.status_code == 200: | ||
data = response.json() | ||
description = data.get('data', {}).get('Media', {}).get('description', 'No description available') | ||
return self.strip_html_tags(description) | ||
else: | ||
return f"Error fetching anime description: {response.status_code}" | ||
|
||
def get_manga_description(self, name): | ||
query = ''' | ||
query ($name: String!) { | ||
Media(search: $name, type: MANGA) { | ||
description | ||
} | ||
} | ||
''' | ||
variables = {'name': name} | ||
response = requests.post(self.url, json={'query': query, 'variables': variables}) | ||
if response.status_code == 200: | ||
data = response.json() | ||
description = data.get('data', {}).get('Media', {}).get('description', 'No description available') | ||
return self.strip_html_tags(description) | ||
else: | ||
return f"Error fetching manga description: {response.status_code}" | ||
|
||
def get_character_description(self, name): | ||
query = ''' | ||
query ($name: String!) { | ||
Character(search: $name) { | ||
description | ||
} | ||
} | ||
''' | ||
variables = {'name': name} | ||
response = requests.post(self.url, json={'query': query, 'variables': variables}) | ||
if response.status_code == 200: | ||
data = response.json() | ||
description = data.get('data', {}).get('Character', {}).get('description', 'No description available') | ||
return self.strip_html_tags(description) | ||
else: | ||
return f"Error fetching character description: {response.status_code}" | ||
|
||
def get_anime_details(self, name): | ||
query = ''' | ||
query ($name: String!) { | ||
Media(search: $name, type: ANIME) { | ||
description | ||
averageScore | ||
status | ||
} | ||
} | ||
''' | ||
variables = {'name': name} | ||
response = requests.post(self.url, json={'query': query, 'variables': variables}) | ||
if response.status_code == 200: | ||
data = response.json() | ||
details = data.get('data', {}).get('Media', {}) | ||
description = details.get('description', 'No description available') | ||
average_score = details.get('averageScore', 'No average score available') | ||
status = details.get('status', 'No status available') | ||
return { | ||
'description': self.strip_html_tags(description), | ||
'averageScore': average_score, | ||
'status': status | ||
} | ||
else: | ||
return f"Error fetching anime details: {response.status_code}" | ||
|
||
def get_manga_details(self, name): | ||
query = ''' | ||
query ($name: String!) { | ||
Media(search: $name, type: MANGA) { | ||
description | ||
averageScore | ||
status | ||
} | ||
} | ||
''' | ||
variables = {'name': name} | ||
response = requests.post(self.url, json={'query': query, 'variables': variables}) | ||
if response.status_code == 200: | ||
data = response.json() | ||
details = data.get('data', {}).get('Media', {}) | ||
description = details.get('description', 'No description available') | ||
average_score = details.get('averageScore', 'No average score available') | ||
status = details.get('status', 'No status available') | ||
return { | ||
'description': self.strip_html_tags(description), | ||
'averageScore': average_score, | ||
'status': status | ||
} | ||
else: | ||
return f"Error fetching manga details: {response.status_code}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
token = '' # add your discord token | ||
|
||
aiclient =('') # Add your c.ai API key here | ||
|
||
channel_id = '' | ||
|
||
lama="" | ||
|
||
|
||
#1292207460131667969 | ||
#1264627297411924140 | ||
|
||
|
||
# if you dont knoe how to | ||
|
||
# for discord watch this one = https://www.youtube.com/watch?v=dR9n1zmw-Go | ||
|
||
# for c.ai look this one = https://github.com/kramcat/CharacterAI | ||
|
||
# lama or anymodel used is from https://openrouter.ai |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from transformers import BlipProcessor, BlipForConditionalGeneration | ||
from PIL import Image | ||
import torch | ||
import os | ||
|
||
class ImageCaptioning: | ||
def __init__(self): | ||
# Load pre-trained processor and model for image captioning | ||
self.processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") | ||
self.model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") | ||
self.supported_extensions = (".jpg", ".jpeg", ".png", ".bmp", ".gif", ".tiff") | ||
|
||
def load_image(self, image_path): | ||
# Check if the file exists and has a supported extension | ||
if not os.path.exists(image_path): | ||
print("File does not exist. Please provide a valid file path.") | ||
return None | ||
|
||
if not image_path.lower().endswith(self.supported_extensions): | ||
print("Unsupported file type. Please provide an image with a supported extension.") | ||
return None | ||
|
||
try: | ||
# Open the image file | ||
image = Image.open(image_path) | ||
return image | ||
except Exception as e: | ||
print(f"Error loading image: {e}") | ||
return None | ||
|
||
def generate_caption(self, image_path): | ||
# Load the image | ||
image = self.load_image(image_path) | ||
if image is None: | ||
return None | ||
|
||
# Convert the image to RGB mode if it's not already | ||
if image.mode != "RGB": | ||
image = image.convert("RGB") | ||
|
||
# Preprocess the image for the BLIP model | ||
inputs = self.processor(image, return_tensors="pt") | ||
|
||
# Perform inference (Image Captioning) | ||
with torch.no_grad(): | ||
generated_ids = self.model.generate(**inputs) | ||
|
||
# Decode the generated caption | ||
generated_caption = self.processor.decode(generated_ids[0], skip_special_tokens=True) | ||
|
||
return generated_caption |
Oops, something went wrong.