├── requirements.txt
├── config.py
├── README.md
└── gemini.py
/requirements.txt:
--------------------------------------------------------------------------------
1 | pyrofork
2 | pillow
3 | google-generativeai
--------------------------------------------------------------------------------
/config.py:
--------------------------------------------------------------------------------
1 | # Pyrogram setup
2 | API_ID = "12345678" # Replace this API ID with your actual API ID
3 | API_HASH = "XXXXXXXXXXXXXX" # Replace this API HASH with your actual API HASH
4 | BOT_TOKEN = "XXXXXXXXXXXXXXXXXXX" # Replace this BOT_TOKEN
5 |
6 | # Google Api Key
7 | GOOGLE_API_KEY = "XXXXXXXXXXXXXXXXXXXX" # Replace this Google Api Key
8 | MODEL_NAME = "gemini-1.5-flash" # Don't Change this model
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #
Gemini Pro Telegram Bot 🌌
2 |
3 |
4 | Gemini Pro: An AI-powered Telegram bot script for generating text and image-based responses using Gemini AI
5 |
6 |
7 |
8 | ## 🌟 Features
9 |
10 | - 🍪 **Text Prompt Response**: Accepts text prompts and generates text.
11 | - 🖼️ **Image Recognition**: Can read and interpret images.
12 |
13 | ## Requirements
14 |
15 | Before you begin, ensure you have met the following requirements:
16 |
17 | - Python 3.9 or higher.
18 | - `pyrofork`, `google-generativeai`, and `pillow` libraries.
19 | - A Telegram bot token (you can get one from [@BotFather](https://t.me/BotFather) on Telegram).
20 | - API ID and Hash: You can get these by creating an application on [my.telegram.org](https://my.telegram.org).
21 | - To Get `GOOGLE_API_KEY` Open [GOOGLE_API_KEY](https://makersuite.google.com/app/apikey).
22 |
23 | ## Installation
24 |
25 | To install `pyrofork`, `google-generativeai`, and `pillow`, run the following command:
26 |
27 | ```bash
28 | pip install pyrofork google-generativeai pillow
29 | ```
30 |
31 | Alternatively, you can install the required dependencies using the `requirements.txt` file:
32 |
33 | ```bash
34 | pip install -r requirements.txt
35 | ```
36 |
37 | **Note: If you previously installed `pyrogram`, uninstall it before installing `pyrofork`.**
38 |
39 | ## Configuration
40 |
41 | 1. Open the `config.py` file in your favorite text editor.
42 | 2. Replace the placeholders for `API_ID`, `API_HASH`, `GOOGLE_API_KEY`, and `BOT_TOKEN` with your actual values:
43 | - **`API_ID`**: Your API ID from [my.telegram.org](https://my.telegram.org).
44 | - **`API_HASH`**: Your API Hash from [my.telegram.org](https://my.telegram.org).
45 | - **`GOOGLE_API_KEY`**: To get Google API Key [Click Here](https://makersuite.google.com/app/apikey).
46 | - **`BOT_TOKEN`**: The token you obtained from [@BotFather](https://t.me/BotFather).
47 |
48 | ## Deploy the Bot
49 |
50 | ```sh
51 | git clone https://github.com/abirxdhack/GeminiProBots
52 | cd GeminiProBot
53 | pip install -r requirements.txt
54 | python gemini.py
55 | ```
56 |
57 | ## Usage 🛠️
58 |
59 | The bot supports the following commands:
60 |
61 | - `/gem `: Generates a response based on a provided text prompt.
62 | - `/gemi `: Generates a response based on a provided text prompt.
63 | - `/gemini `: Generates a response based on a provided text prompt.
64 | - `.gem `: Generates a response based on a provided text prompt.
65 | - `.gemi `: Generates a response based on a provided text prompt.
66 | - `.gemini `: Generates a response based on a provided text prompt.
67 | - `/imgai `: Generates a response based on an image. Ensure you reply to an image with the /imgai command. Optionally, you can provide a prompt along with the command, like `/imgai What is this?`, while replying to a photo to get a more specific response.
68 | - `.imgai `: Generates a response based on an image. Ensure you reply to an image with the /imgai command. Optionally, you can provide a prompt along with the command, like `/imgai What is this?`, while replying to a photo to get a more specific response.
69 | ## Owner ⚡️
70 |
71 | - Name: Bisnu Ray
72 | - Telegram: [@TheSmartBisnu](https://t.me/TheSmartBisnu)
73 |
74 | ## Note
75 | I Just Added Start Message And Added . / Support + Group So Main Credit TheSmartBisnu
76 |
77 | ## Update ⚡️
78 |
79 | - Name: Abir Arafat Chawdhury
80 | - Telegram: [@abirxdhackz](https://t.me/abirxdhackz)
81 |
82 | Feel free to reach out if you have any questions or feedback.
83 |
--------------------------------------------------------------------------------
/gemini.py:
--------------------------------------------------------------------------------
1 | import os
2 | import io
3 | import logging
4 | import PIL.Image
5 | from pyrogram.types import Message
6 | import google.generativeai as genai
7 | from pyrogram import Client, filters
8 | from pyrogram.enums import ParseMode
9 | from config import API_ID, API_HASH, BOT_TOKEN, GOOGLE_API_KEY, MODEL_NAME
10 |
11 | app = Client(
12 | "gemini_session",
13 | api_id=API_ID,
14 | api_hash=API_HASH,
15 | bot_token=BOT_TOKEN,
16 | parse_mode=ParseMode.MARKDOWN
17 | )
18 |
19 | genai.configure(api_key=GOOGLE_API_KEY)
20 |
21 | model = genai.GenerativeModel(MODEL_NAME)
22 |
23 | @app.on_message(filters.command("start"))
24 | async def start(client: Client, message: Message):
25 | start_message = (
26 | "**Welcome to Gemini AI Bot!**\n\n"
27 | "I am here to assist you with advanced AI capabilities. Here are my commands:\n\n"
28 | "➢ **/gem [Question]** - Ask a question to Gemini AI.\n"
29 | " - Example: `/gem How does photosynthesis work?` (Returns an explanation of photosynthesis)\n\n"
30 | "➢ **/imgai [Optional Prompt]** - Analyze an image or generate a response based on it.\n"
31 | " - Basic Usage: Reply to an image with `/imgai` to get a general analysis.\n"
32 | " - With Prompt: Reply to an image with `/imgai [Your Prompt]` to get a specific response.\n"
33 | " - Example 1: Reply to an image with `/imgai` (Provides a general description of the image).\n"
34 | " - Example 2: Reply to an image with `/imgai What is this?` (Provides a specific response based on the prompt and image).\n\n"
35 | "> **NOTE:**\n"
36 | "1️⃣ These tools leverage advanced AI models for accurate and detailed outputs."
37 | )
38 | await message.reply_text(start_message)
39 |
40 | @app.on_message(filters.command(["gem","gemi","gemini"], prefixes=["/", "."]) & (filters.private | filters.group))
41 | async def gemi_handler(client: Client, message: Message):
42 | loading_message = None
43 | try:
44 | loading_message = await message.reply_text("**Generating response ⚡️ please wait...**")
45 |
46 | if len(message.text.strip()) <= 5:
47 | await message.reply_text("**Provide a prompt after the command ❌ **")
48 | return
49 |
50 | prompt = message.text.split(maxsplit=1)[1]
51 | response = model.generate_content(prompt)
52 |
53 | response_text = response.text
54 | if len(response_text) > 4000:
55 | parts = [response_text[i:i + 4000] for i in range(0, len(response_text), 4000)]
56 | for part in parts:
57 | await message.reply_text(part)
58 | else:
59 | await message.reply_text(response_text)
60 |
61 | except Exception as e:
62 | await message.reply_text(f"**An error occurred ❌**")
63 | finally:
64 | if loading_message:
65 | await loading_message.delete()
66 |
67 | @app.on_message(filters.command(["imgai"], prefixes=["/", "."]) & (filters.private | filters.group))
68 | async def generate_from_image(client: Client, message: Message):
69 | if not message.reply_to_message or not message.reply_to_message.photo:
70 | await message.reply_text("**Please reply to a photo for a response ❌ **")
71 | return
72 |
73 | prompt = message.command[1] if len(message.command) > 1 else message.reply_to_message.caption or "Describe this image."
74 |
75 | processing_message = await message.reply_text("**Processing The Image And Generating Response ⚡️ please wait...**")
76 |
77 | try:
78 | img_data = await client.download_media(message.reply_to_message, in_memory=True)
79 | img = PIL.Image.open(io.BytesIO(img_data.getbuffer()))
80 |
81 | response = model.generate_content([prompt, img])
82 | response_text = response.text
83 |
84 | await message.reply_text(response_text, parse_mode=None)
85 | except Exception as e:
86 | logging.error(f"Error during image analysis: {e}")
87 | await message.reply_text("**An error occurred❌ **")
88 | finally:
89 | await processing_message.delete()
90 |
91 | if __name__ == '__main__':
92 | app.run()
93 |
--------------------------------------------------------------------------------