Spaces:
Runtime error
Runtime error
Commit
·
16d62e2
1
Parent(s):
516038a
✨ Enhance app functionality: load environment variables, add new math operations, and improve memory management; update requirements and .gitignore. Add Purify converter for html to markdown process
Browse files- .gitignore +1 -0
- Purify.py +100 -0
- app.py +140 -124
- requirements.txt +0 -1
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
Purify.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from bs4 import BeautifulSoup, Tag
|
| 2 |
+
import datetime
|
| 3 |
+
import requests
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
Url = 'https://huggingface.co'
|
| 7 |
+
|
| 8 |
+
NoisePatterns = {
|
| 9 |
+
'(No)Script': r'<[ ]*(script|noscript)[^>]*?>.*?<\/[ ]*\1[ ]*>',
|
| 10 |
+
'Style': r'<[ ]*(style)[^>]*?>.*?<\/[ ]*\1[ ]*>',
|
| 11 |
+
'Svg': r'<[ ]*(svg)[^>]*?>.*?<\/[ ]*\1[ ]*>',
|
| 12 |
+
|
| 13 |
+
'Meta+Link': r'<[ ]*(meta|link)[^>]*?[\/]?[ ]*>',
|
| 14 |
+
'Comment': r'<[ ]*!--.*?--[ ]*>',
|
| 15 |
+
'Base64Img': r'<[ ]*img[^>]+src="data:image\/[^;]+;base64,[^"]+"[^>]*[\/]?[ ]*>',
|
| 16 |
+
'DocType': r'<!(DOCTYPE|doctype)[ ]*[a-z]*>',
|
| 17 |
+
|
| 18 |
+
'DataAttributes': r'[ ]+data-[\w-]+="[^"]*"',
|
| 19 |
+
'Classes': r'[ ]+class="[^"]*"',
|
| 20 |
+
'EmptyAttributes': r'[ ]+[a-z-]+=""',
|
| 21 |
+
'DateTime': r'[ ]+datetime="[^"]*"',
|
| 22 |
+
|
| 23 |
+
'EmptyTags': r'(?:<[ ]*([a-z]{1,10})[^>]*>[ \t\r\n]*){1,5}(?:<\/[ ]*\1[ ]*>){1,5}',
|
| 24 |
+
'EmptyLines': r'^[ \t]*\r?\n',
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
def RemoveNoise(RawHtml: str) -> str:
|
| 28 |
+
'''Remove noise from HTML content.
|
| 29 |
+
Args:
|
| 30 |
+
RawHtml (str): The raw HTML content.
|
| 31 |
+
Returns:
|
| 32 |
+
str: Cleaned HTML content without noise.
|
| 33 |
+
'''
|
| 34 |
+
CleanedHtml = RawHtml
|
| 35 |
+
OriginalCharCount = len(RawHtml)
|
| 36 |
+
for PatternName, Pattern in NoisePatterns.items():
|
| 37 |
+
if PatternName in ['EmptyLines', 'EmptyTags']: # These patterns are line-based
|
| 38 |
+
CleanedHtml = re.sub(Pattern, '', CleanedHtml, flags=re.MULTILINE)
|
| 39 |
+
else:
|
| 40 |
+
CleanedHtml = re.sub(Pattern, '', CleanedHtml, flags=re.DOTALL | re.IGNORECASE | re.MULTILINE)
|
| 41 |
+
print(f'• Removed {PatternName} noise. Removed {OriginalCharCount - len(CleanedHtml)} characters.')
|
| 42 |
+
OriginalCharCount = len(CleanedHtml)
|
| 43 |
+
return CleanedHtml
|
| 44 |
+
|
| 45 |
+
def FetchHtmlContent(Url: str) -> str | int:
|
| 46 |
+
'''Fetch HTML content from a URL.
|
| 47 |
+
Args:
|
| 48 |
+
Url (str): The URL to fetch HTML content from.
|
| 49 |
+
Returns:
|
| 50 |
+
str: The raw HTML content.
|
| 51 |
+
'''
|
| 52 |
+
Headers = {
|
| 53 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
|
| 54 |
+
}
|
| 55 |
+
Response = requests.get(Url, headers=Headers)
|
| 56 |
+
if Response.status_code == 200:
|
| 57 |
+
return Response.text
|
| 58 |
+
else:
|
| 59 |
+
return Response.status_code
|
| 60 |
+
|
| 61 |
+
Start = datetime.datetime.now()
|
| 62 |
+
RawHtml = FetchHtmlContent(Url)
|
| 63 |
+
if isinstance(RawHtml, str):
|
| 64 |
+
RawCharCount = len(RawHtml)
|
| 65 |
+
|
| 66 |
+
print('Prettifying HTML content...')
|
| 67 |
+
|
| 68 |
+
Soup = BeautifulSoup(RawHtml, 'html.parser')
|
| 69 |
+
PrettifiedHtml = str(Soup.prettify())
|
| 70 |
+
|
| 71 |
+
Title = Soup.title.string if Soup.title else 'No title found'
|
| 72 |
+
MetaDesc = Soup.find('meta', attrs={'name': 'description'})
|
| 73 |
+
Description = MetaDesc.get('content', 'No description found') if isinstance(MetaDesc, Tag) else 'No description found'
|
| 74 |
+
|
| 75 |
+
print('Purifying HTML content...')
|
| 76 |
+
|
| 77 |
+
CleanedHtml = RemoveNoise(PrettifiedHtml)
|
| 78 |
+
|
| 79 |
+
CleanedCharCount = len(CleanedHtml)
|
| 80 |
+
Ratio = CleanedCharCount / RawCharCount if RawCharCount > 0 else 0
|
| 81 |
+
|
| 82 |
+
Summary = [
|
| 83 |
+
'<!-- --- Purification Summary ---',
|
| 84 |
+
f'URL: {Url}',
|
| 85 |
+
f'Title: {Title}',
|
| 86 |
+
f'Description: {Description}',
|
| 87 |
+
f'Time of Fetch: {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} (Took {datetime.datetime.now() - Start})',
|
| 88 |
+
f'Noise Removal Ratio: {Ratio:.2%} (lower is better)',
|
| 89 |
+
f'Characters: {RawCharCount} -> {CleanedCharCount} ({RawCharCount - CleanedCharCount} characters removed)',
|
| 90 |
+
'----------------------------- -->'
|
| 91 |
+
]
|
| 92 |
+
for Line in Summary:
|
| 93 |
+
print(Line)
|
| 94 |
+
|
| 95 |
+
with open('CleanedHtml.html', 'w', encoding='utf-8') as File:
|
| 96 |
+
for Line in Summary:
|
| 97 |
+
File.write(Line + '\n')
|
| 98 |
+
File.write(CleanedHtml)
|
| 99 |
+
else:
|
| 100 |
+
print(f'Failed to fetch HTML content. Status code: {RawHtml}')
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from pymongo import MongoClient
|
|
|
|
| 2 |
from typing import Literal
|
| 3 |
from bson import ObjectId
|
| 4 |
from io import StringIO
|
|
@@ -12,6 +13,7 @@ import gradio
|
|
| 12 |
import sys
|
| 13 |
import os
|
| 14 |
|
|
|
|
| 15 |
MemoryPassword = os.getenv('MEMORY_PASSWORD')
|
| 16 |
MongoURI = os.getenv('MONGO_URI')
|
| 17 |
DatabaseName = 'MCP-Utilities'
|
|
@@ -66,12 +68,12 @@ def Dice(Sides: int = 6) -> int:
|
|
| 66 |
'''
|
| 67 |
return random.randint(1, Sides)
|
| 68 |
|
| 69 |
-
def Math(Num1: float, Num2: float, Operation: Literal['add', 'subtract', 'multiply', 'divide']) -> float | str:
|
| 70 |
'''Perform a mathematical operation on two numbers.
|
| 71 |
Args:
|
| 72 |
Num1 (float): The first number.
|
| 73 |
Num2 (float): The second number.
|
| 74 |
-
Operation (Literal['add', 'subtract', 'multiply', 'divide']): The operation to perform.
|
| 75 |
Returns:
|
| 76 |
float | str: The result of the operation or an error message.
|
| 77 |
'''
|
|
@@ -79,7 +81,9 @@ def Math(Num1: float, Num2: float, Operation: Literal['add', 'subtract', 'multip
|
|
| 79 |
'add': lambda x, y: x + y,
|
| 80 |
'subtract': lambda x, y: x - y,
|
| 81 |
'multiply': lambda x, y: x * y,
|
| 82 |
-
'divide': lambda x, y: x / y if y != 0 else 'Error: Division by zero'
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
if Operation in Operations:
|
|
@@ -116,6 +120,8 @@ def Ping(Host: str, Count: int = 8) -> str:
|
|
| 116 |
Returns:
|
| 117 |
str: The result of the ping command.
|
| 118 |
'''
|
|
|
|
|
|
|
| 119 |
Durations = []
|
| 120 |
for _ in range(Count):
|
| 121 |
try:
|
|
@@ -199,18 +205,19 @@ def Base64(Text: str, Choice: Literal['encode', 'decode']) -> str:
|
|
| 199 |
else:
|
| 200 |
return 'Error: Invalid choice.'
|
| 201 |
|
| 202 |
-
def Hash(Text: str, Algorithm: Literal['md5', 'sha1', 'sha256']) -> str:
|
| 203 |
'''Hash the input text using the specified algorithm.
|
| 204 |
Args:
|
| 205 |
Text (str): The text to hash.
|
| 206 |
-
Algorithm (Literal['md5', 'sha1', 'sha256']): The hashing algorithm to use.
|
| 207 |
Returns:
|
| 208 |
str: The resulting hash.
|
| 209 |
'''
|
| 210 |
Hashes = {
|
| 211 |
'md5': hashlib.md5,
|
| 212 |
'sha1': hashlib.sha1,
|
| 213 |
-
'sha256': hashlib.sha256
|
|
|
|
| 214 |
}
|
| 215 |
|
| 216 |
if Algorithm in Hashes:
|
|
@@ -223,7 +230,9 @@ def Hash(Text: str, Algorithm: Literal['md5', 'sha1', 'sha256']) -> str:
|
|
| 223 |
# ╰────────────────────╯
|
| 224 |
|
| 225 |
def SaveMemory(Text: str, Password: str) -> str:
|
| 226 |
-
'''
|
|
|
|
|
|
|
| 227 |
try:
|
| 228 |
if Collection is None:
|
| 229 |
return 'Error: MongoDB connection not available'
|
|
@@ -242,7 +251,9 @@ def SaveMemory(Text: str, Password: str) -> str:
|
|
| 242 |
return f'Error: {str(e)}'
|
| 243 |
|
| 244 |
def ListMemories(Password: str) -> str:
|
| 245 |
-
'''
|
|
|
|
|
|
|
| 246 |
try:
|
| 247 |
if Collection is None:
|
| 248 |
return 'Error: MongoDB connection not available'
|
|
@@ -266,7 +277,9 @@ def ListMemories(Password: str) -> str:
|
|
| 266 |
return f'Error: {str(e)}'
|
| 267 |
|
| 268 |
def DeleteMemory(MemoryID: str, Password: str) -> str:
|
| 269 |
-
'''
|
|
|
|
|
|
|
| 270 |
try:
|
| 271 |
if Collection is None:
|
| 272 |
return 'Error: MongoDB connection not available'
|
|
@@ -287,7 +300,9 @@ def DeleteMemory(MemoryID: str, Password: str) -> str:
|
|
| 287 |
return f'Error: {str(e)}'
|
| 288 |
|
| 289 |
def SearchMemories(Query: str, Password: str) -> str:
|
| 290 |
-
'''
|
|
|
|
|
|
|
| 291 |
try:
|
| 292 |
if Collection is None:
|
| 293 |
return 'Error: MongoDB connection not available'
|
|
@@ -323,122 +338,123 @@ def SearchMemories(Query: str, Password: str) -> str:
|
|
| 323 |
|
| 324 |
with gradio.Blocks(
|
| 325 |
title='MCP Utilities 🛠️',
|
| 326 |
-
theme=Theme
|
| 327 |
-
fill_height=True,
|
| 328 |
-
fill_width=True
|
| 329 |
) as App:
|
| 330 |
gradio.Markdown('# MCP Utilities 🛠️')
|
| 331 |
-
with gradio.
|
| 332 |
-
with gradio.TabItem('
|
| 333 |
-
with gradio.
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
App.launch(
|
| 444 |
mcp_server=True
|
|
|
|
| 1 |
from pymongo import MongoClient
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
from typing import Literal
|
| 4 |
from bson import ObjectId
|
| 5 |
from io import StringIO
|
|
|
|
| 13 |
import sys
|
| 14 |
import os
|
| 15 |
|
| 16 |
+
load_dotenv()
|
| 17 |
MemoryPassword = os.getenv('MEMORY_PASSWORD')
|
| 18 |
MongoURI = os.getenv('MONGO_URI')
|
| 19 |
DatabaseName = 'MCP-Utilities'
|
|
|
|
| 68 |
'''
|
| 69 |
return random.randint(1, Sides)
|
| 70 |
|
| 71 |
+
def Math(Num1: float, Num2: float, Operation: Literal['add', 'subtract', 'multiply', 'divide', 'modulus', 'exponent']) -> float | str:
|
| 72 |
'''Perform a mathematical operation on two numbers.
|
| 73 |
Args:
|
| 74 |
Num1 (float): The first number.
|
| 75 |
Num2 (float): The second number.
|
| 76 |
+
Operation (Literal['add', 'subtract', 'multiply', 'divide', 'modulus', 'exponent']): The operation to perform.
|
| 77 |
Returns:
|
| 78 |
float | str: The result of the operation or an error message.
|
| 79 |
'''
|
|
|
|
| 81 |
'add': lambda x, y: x + y,
|
| 82 |
'subtract': lambda x, y: x - y,
|
| 83 |
'multiply': lambda x, y: x * y,
|
| 84 |
+
'divide': lambda x, y: x / y if y != 0 else 'Error: Division by zero',
|
| 85 |
+
'modulus': lambda x, y: x % y if y != 0 else 'Error: Division by zero',
|
| 86 |
+
'exponent': lambda x, y: x ** y,
|
| 87 |
}
|
| 88 |
|
| 89 |
if Operation in Operations:
|
|
|
|
| 120 |
Returns:
|
| 121 |
str: The result of the ping command.
|
| 122 |
'''
|
| 123 |
+
if not Host:
|
| 124 |
+
return 'Error: Host cannot be empty'
|
| 125 |
Durations = []
|
| 126 |
for _ in range(Count):
|
| 127 |
try:
|
|
|
|
| 205 |
else:
|
| 206 |
return 'Error: Invalid choice.'
|
| 207 |
|
| 208 |
+
def Hash(Text: str, Algorithm: Literal['md5', 'sha1', 'sha256', 'sha512']) -> str:
|
| 209 |
'''Hash the input text using the specified algorithm.
|
| 210 |
Args:
|
| 211 |
Text (str): The text to hash.
|
| 212 |
+
Algorithm (Literal['md5', 'sha1', 'sha256', 'sha512']): The hashing algorithm to use.
|
| 213 |
Returns:
|
| 214 |
str: The resulting hash.
|
| 215 |
'''
|
| 216 |
Hashes = {
|
| 217 |
'md5': hashlib.md5,
|
| 218 |
'sha1': hashlib.sha1,
|
| 219 |
+
'sha256': hashlib.sha256,
|
| 220 |
+
'sha512': hashlib.sha512
|
| 221 |
}
|
| 222 |
|
| 223 |
if Algorithm in Hashes:
|
|
|
|
| 230 |
# ╰────────────────────╯
|
| 231 |
|
| 232 |
def SaveMemory(Text: str, Password: str) -> str:
|
| 233 |
+
'''
|
| 234 |
+
Save a memory with the given text to MongoDB.
|
| 235 |
+
'''
|
| 236 |
try:
|
| 237 |
if Collection is None:
|
| 238 |
return 'Error: MongoDB connection not available'
|
|
|
|
| 251 |
return f'Error: {str(e)}'
|
| 252 |
|
| 253 |
def ListMemories(Password: str) -> str:
|
| 254 |
+
'''
|
| 255 |
+
List all saved memories from MongoDB.
|
| 256 |
+
'''
|
| 257 |
try:
|
| 258 |
if Collection is None:
|
| 259 |
return 'Error: MongoDB connection not available'
|
|
|
|
| 277 |
return f'Error: {str(e)}'
|
| 278 |
|
| 279 |
def DeleteMemory(MemoryID: str, Password: str) -> str:
|
| 280 |
+
'''
|
| 281 |
+
Delete a memory by its MongoDB ObjectId.
|
| 282 |
+
'''
|
| 283 |
try:
|
| 284 |
if Collection is None:
|
| 285 |
return 'Error: MongoDB connection not available'
|
|
|
|
| 300 |
return f'Error: {str(e)}'
|
| 301 |
|
| 302 |
def SearchMemories(Query: str, Password: str) -> str:
|
| 303 |
+
'''
|
| 304 |
+
Search memories by text content.
|
| 305 |
+
'''
|
| 306 |
try:
|
| 307 |
if Collection is None:
|
| 308 |
return 'Error: MongoDB connection not available'
|
|
|
|
| 338 |
|
| 339 |
with gradio.Blocks(
|
| 340 |
title='MCP Utilities 🛠️',
|
| 341 |
+
theme=Theme
|
|
|
|
|
|
|
| 342 |
) as App:
|
| 343 |
gradio.Markdown('# MCP Utilities 🛠️')
|
| 344 |
+
with gradio.TabItem('General Tools 🛠️'):
|
| 345 |
+
with gradio.TabItem('Weather 🌤️'):
|
| 346 |
+
with gradio.Group():
|
| 347 |
+
LocationInput = gradio.Textbox(label='Location 🌍', placeholder='Enter a location for weather', lines=1, max_lines=1)
|
| 348 |
+
WeatherOutput = gradio.Text(label='Weather ☁️', interactive=False)
|
| 349 |
+
WeatherBtn = gradio.Button('Get Weather 🔎', variant='primary')
|
| 350 |
+
WeatherBtn.click(Weather, inputs=LocationInput, outputs=WeatherOutput)
|
| 351 |
+
|
| 352 |
+
with gradio.TabItem('Date & Time 📅'):
|
| 353 |
+
with gradio.Group():
|
| 354 |
+
DateOutput = gradio.Text(label='Date 📅', interactive=False)
|
| 355 |
+
DateBtn = gradio.Button('Get Date 📅', variant='primary')
|
| 356 |
+
DateBtn.click(Date, outputs=DateOutput)
|
| 357 |
+
|
| 358 |
+
with gradio.TabItem('Code Execution 🐍'):
|
| 359 |
+
with gradio.Group():
|
| 360 |
+
CodeInput = gradio.Textbox(label='Python Code 🐍', placeholder='Enter Python code to execute', lines=5)
|
| 361 |
+
CodeOutput = gradio.Text(label='Execution Output 📜', interactive=False)
|
| 362 |
+
CodeBtn = gradio.Button('Execute Code ▶️', variant='primary')
|
| 363 |
+
CodeBtn.click(ExecuteCode, inputs=CodeInput, outputs=CodeOutput)
|
| 364 |
+
|
| 365 |
+
with gradio.TabItem('Dice Roller 🎲'):
|
| 366 |
+
with gradio.Group():
|
| 367 |
+
DiceSides = gradio.Number(label='Sides of Dice 🔢', value=6, minimum=1, maximum=100)
|
| 368 |
+
DiceOutput = gradio.Text(label='Dice Roll Result 🎲', interactive=False)
|
| 369 |
+
DiceBtn = gradio.Button('Roll Dice ♻️', variant='primary')
|
| 370 |
+
DiceBtn.click(Dice, inputs=DiceSides, outputs=DiceOutput)
|
| 371 |
+
|
| 372 |
+
with gradio.TabItem('Math Operations ➕➖✖️➗'):
|
| 373 |
+
with gradio.Group():
|
| 374 |
+
Num1Input = gradio.Number(label='Number 1 1️⃣', value=0)
|
| 375 |
+
Num2Input = gradio.Number(label='Number 2 2️⃣', value=0)
|
| 376 |
+
OperationInput = gradio.Radio(label='Operation 🔣', choices=['add', 'subtract', 'multiply', 'divide', 'modulus', 'exponent'], value='add', interactive=True)
|
| 377 |
+
MathOutput = gradio.Text(label='Math Result 🟰', interactive=False)
|
| 378 |
+
MathBtn = gradio.Button('Calculate 🧮', variant='primary')
|
| 379 |
+
MathBtn.click(Math, inputs=[Num1Input, Num2Input, OperationInput], outputs=MathOutput)
|
| 380 |
+
|
| 381 |
+
with gradio.TabItem('Ping Host 📡'):
|
| 382 |
+
with gradio.Group():
|
| 383 |
+
PingInput = gradio.Textbox(label='Host to Ping 🌐', placeholder='Enter host (e.g., google.com)', lines=1, max_lines=1)
|
| 384 |
+
PingCount = gradio.Number(label='Ping Count 🔢', value=8, minimum=1, maximum=100)
|
| 385 |
+
PingOutput = gradio.Text(label='Ping Result 📡', interactive=False)
|
| 386 |
+
PingBtn = gradio.Button('Ping Host 📡', variant='primary')
|
| 387 |
+
PingBtn.click(Ping, inputs=[PingInput, PingCount], outputs=PingOutput)
|
| 388 |
+
|
| 389 |
+
with gradio.TabItem('Fun & Entertainment 🎭'):
|
| 390 |
+
with gradio.TabItem('Random Joke 😂'):
|
| 391 |
+
with gradio.Group():
|
| 392 |
+
JokeOutput = gradio.Text(label='Random Joke 😂', interactive=False)
|
| 393 |
+
JokeBtn = gradio.Button('Get Joke 🎪', variant='primary')
|
| 394 |
+
JokeBtn.click(Joke, outputs=JokeOutput)
|
| 395 |
+
|
| 396 |
+
with gradio.TabItem('Random Fact 🧠'):
|
| 397 |
+
with gradio.Group():
|
| 398 |
+
FactOutput = gradio.Text(label='Random Fact 🧠', interactive=False)
|
| 399 |
+
FactBtn = gradio.Button('Get Fact 📚', variant='primary')
|
| 400 |
+
FactBtn.click(Fact, outputs=FactOutput)
|
| 401 |
+
|
| 402 |
+
with gradio.TabItem('Text Processing 📝'):
|
| 403 |
+
with gradio.TabItem('Text Reversal 🔄'):
|
| 404 |
+
with gradio.Group():
|
| 405 |
+
ReverseInput = gradio.Textbox(label='Text to Reverse 🔄', placeholder='Enter text to reverse', lines=3)
|
| 406 |
+
ReverseOutput = gradio.Text(label='Reversed Text ↩️', interactive=False)
|
| 407 |
+
ReverseBtn = gradio.Button('Reverse Text 🔄', variant='primary')
|
| 408 |
+
ReverseBtn.click(Reverse, inputs=ReverseInput, outputs=ReverseOutput)
|
| 409 |
+
|
| 410 |
+
with gradio.TabItem('Word Count 📏'):
|
| 411 |
+
with gradio.Group():
|
| 412 |
+
WordCountInput = gradio.Textbox(label='Text for Word Count 📏', placeholder='Enter text to count words', lines=3)
|
| 413 |
+
WordCountChoice = gradio.Radio(label='Count Type 🔢', choices=['words', 'characters'], value='words', interactive=True)
|
| 414 |
+
WordCountOutput = gradio.Text(label='Word Count Result 📊', interactive=False)
|
| 415 |
+
WordCountBtn = gradio.Button('Count Words 📈', variant='primary')
|
| 416 |
+
WordCountBtn.click(WordCount, inputs=[WordCountInput, WordCountChoice], outputs=WordCountOutput)
|
| 417 |
+
|
| 418 |
+
with gradio.TabItem('Base64 Encoding/Decoding 📦'):
|
| 419 |
+
with gradio.Group():
|
| 420 |
+
Base64Input = gradio.Textbox(label='Text for Base64 📦', placeholder='Enter text to encode/decode', lines=3)
|
| 421 |
+
Base64Choice = gradio.Radio(label='Operation 🔄', choices=['encode', 'decode'], value='encode', interactive=True)
|
| 422 |
+
Base64Output = gradio.Text(label='Base64 Result 📦', interactive=False)
|
| 423 |
+
Base64Btn = gradio.Button('Process Base64 📦', variant='primary')
|
| 424 |
+
Base64Btn.click(Base64, inputs=[Base64Input, Base64Choice], outputs=Base64Output)
|
| 425 |
+
|
| 426 |
+
with gradio.TabItem('Hashing 🔐'):
|
| 427 |
+
with gradio.Group():
|
| 428 |
+
HashInput = gradio.Textbox(label='Text to Hash 🔐', placeholder='Enter text to hash', lines=3)
|
| 429 |
+
HashChoice = gradio.Radio(label='Hashing Algorithm 🔄', choices=['md5', 'sha1', 'sha256', 'sha512'], value='md5', interactive=True)
|
| 430 |
+
HashOutput = gradio.Text(label='Hash Result 🔐', interactive=False)
|
| 431 |
+
HashBtn = gradio.Button('Generate Hash 🔐', variant='primary')
|
| 432 |
+
HashBtn.click(Hash, inputs=[HashInput, HashChoice], outputs=HashOutput)
|
| 433 |
+
|
| 434 |
+
with gradio.TabItem('Memory Tools 💾'):
|
| 435 |
+
MemoryPasswordInput = gradio.Textbox(label='Password 🔐', placeholder='Enter memory password', type='password', lines=1)
|
| 436 |
+
with gradio.TabItem('Save Memory 💾'):
|
| 437 |
+
with gradio.Group():
|
| 438 |
+
SaveInput = gradio.Textbox(label='Memory Text 💭', placeholder='Enter text to save', lines=3)
|
| 439 |
+
SaveBtn = gradio.Button('Save Memory 💾', variant='primary')
|
| 440 |
+
SaveBtn.click(SaveMemory, inputs=[SaveInput, MemoryPasswordInput], outputs=gradio.Text(label='Result'))
|
| 441 |
+
|
| 442 |
+
with gradio.TabItem('Delete Memory 🗑️'):
|
| 443 |
+
with gradio.Group():
|
| 444 |
+
DeleteInput = gradio.Textbox(label='Memory ID 🗑️', placeholder='Enter ObjectId to delete', lines=1)
|
| 445 |
+
DeleteBtn = gradio.Button('Delete Memory 🗑️', variant='secondary')
|
| 446 |
+
DeleteBtn.click(DeleteMemory, inputs=[DeleteInput, MemoryPasswordInput], outputs=gradio.Text(label='Result'))
|
| 447 |
+
|
| 448 |
+
with gradio.TabItem('List Memories 📄'):
|
| 449 |
+
with gradio.Group():
|
| 450 |
+
ListBtn = gradio.Button('List All Memories 📄', variant='primary')
|
| 451 |
+
ListBtn.click(ListMemories, inputs=MemoryPasswordInput, outputs=gradio.Text(label='Memories'))
|
| 452 |
+
|
| 453 |
+
with gradio.TabItem('Search Memories 🔍'):
|
| 454 |
+
with gradio.Group():
|
| 455 |
+
SearchInput = gradio.Textbox(label='Search Query 🔍', placeholder='Enter search text', lines=1)
|
| 456 |
+
SearchBtn = gradio.Button('Search Memories 🔎', variant='primary')
|
| 457 |
+
SearchBtn.click(SearchMemories, inputs=[SearchInput, MemoryPasswordInput], outputs=gradio.Text(label='Results'))
|
| 458 |
|
| 459 |
App.launch(
|
| 460 |
mcp_server=True
|
requirements.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
-
qrcode
|
| 2 |
pymongo
|
|
|
|
|
|
|
| 1 |
pymongo
|