Hyphonical commited on
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
Files changed (4) hide show
  1. .gitignore +1 -0
  2. Purify.py +100 -0
  3. app.py +140 -124
  4. 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
- '''Save a memory with the given text to MongoDB.'''
 
 
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
- '''List all saved memories from MongoDB.'''
 
 
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
- '''Delete a memory by its MongoDB ObjectId.'''
 
 
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
- '''Search memories by text content.'''
 
 
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.Tabs():
332
- with gradio.TabItem('General Tools 🛠️'):
333
- with gradio.Row():
334
- with gradio.Column():
335
- with gradio.Group():
336
- LocationInput = gradio.Textbox(label='Location 🌍', placeholder='Enter a location for weather', lines=1, max_lines=1)
337
- WeatherOutput = gradio.Text(label='Weather ☁️', interactive=False)
338
- WeatherBtn = gradio.Button('Get Weather 🔎', variant='primary')
339
- WeatherBtn.click(Weather, inputs=LocationInput, outputs=WeatherOutput)
340
-
341
- with gradio.Group():
342
- DateOutput = gradio.Text(label='Date 📅', interactive=False)
343
- DateBtn = gradio.Button('Get Date 📅', variant='primary')
344
- DateBtn.click(Date, outputs=DateOutput)
345
-
346
- with gradio.Group():
347
- CodeInput = gradio.Textbox(label='Python Code 🐍', placeholder='Enter Python code to execute', lines=5)
348
- CodeOutput = gradio.Text(label='Execution Output 📜', interactive=False)
349
- CodeBtn = gradio.Button('Execute Code ▶️', variant='primary')
350
- CodeBtn.click(ExecuteCode, inputs=CodeInput, outputs=CodeOutput)
351
-
352
- with gradio.Column():
353
- with gradio.Group():
354
- DiceSides = gradio.Number(label='Sides of Dice 🔢', value=6, minimum=1, maximum=100)
355
- DiceOutput = gradio.Text(label='Dice Roll Result 🎲', interactive=False)
356
- DiceBtn = gradio.Button('Roll Dice ♻️', variant='primary')
357
- DiceBtn.click(Dice, inputs=DiceSides, outputs=DiceOutput)
358
-
359
- with gradio.Group():
360
- Num1Input = gradio.Number(label='Number 1 1️⃣', value=0)
361
- Num2Input = gradio.Number(label='Number 2 2️⃣', value=0)
362
- OperationInput = gradio.Radio(label='Operation 🔣', choices=['add', 'subtract', 'multiply', 'divide'], value='add', interactive=True)
363
- MathOutput = gradio.Text(label='Math Result 🟰', interactive=False)
364
- MathBtn = gradio.Button('Calculate 🧮', variant='primary')
365
- MathBtn.click(Math, inputs=[Num1Input, Num2Input, OperationInput], outputs=MathOutput)
366
-
367
- with gradio.Group():
368
- PingInput = gradio.Textbox(label='Host to Ping 🌐', placeholder='Enter host (e.g., google.com)', lines=1, max_lines=1)
369
- PingCount = gradio.Number(label='Ping Count 🔢', value=8, minimum=1, maximum=100)
370
- PingOutput = gradio.Text(label='Ping Result 📡', interactive=False)
371
- PingBtn = gradio.Button('Ping Host 📡', variant='primary')
372
- PingBtn.click(Ping, inputs=[PingInput, PingCount], outputs=PingOutput)
373
-
374
- with gradio.TabItem('Fun & Entertainment 🎭'):
375
- with gradio.Row():
376
- with gradio.Column():
377
- with gradio.Group():
378
- JokeOutput = gradio.Text(label='Random Joke 😂', interactive=False)
379
- JokeBtn = gradio.Button('Get Joke 🎪', variant='primary')
380
- JokeBtn.click(Joke, outputs=JokeOutput)
381
-
382
- with gradio.Column():
383
- with gradio.Group():
384
- FactOutput = gradio.Text(label='Random Fact 🧠', interactive=False)
385
- FactBtn = gradio.Button('Get Fact 📚', variant='primary')
386
- FactBtn.click(Fact, outputs=FactOutput)
387
-
388
- with gradio.TabItem('Text Processing 📝'):
389
- with gradio.Row():
390
- with gradio.Column():
391
- with gradio.Group():
392
- ReverseInput = gradio.Textbox(label='Text to Reverse 🔄', placeholder='Enter text to reverse', lines=3)
393
- ReverseOutput = gradio.Text(label='Reversed Text ↩️', interactive=False)
394
- ReverseBtn = gradio.Button('Reverse Text 🔄', variant='primary')
395
- ReverseBtn.click(Reverse, inputs=ReverseInput, outputs=ReverseOutput)
396
-
397
- with gradio.Group():
398
- WordCountInput = gradio.Textbox(label='Text for Word Count 📏', placeholder='Enter text to count words', lines=3)
399
- WordCountChoice = gradio.Radio(label='Count Type 🔢', choices=['words', 'characters'], value='words', interactive=True)
400
- WordCountOutput = gradio.Text(label='Word Count Result 📊', interactive=False)
401
- WordCountBtn = gradio.Button('Count Words 📈', variant='primary')
402
- WordCountBtn.click(WordCount, inputs=[WordCountInput, WordCountChoice], outputs=WordCountOutput)
403
-
404
- with gradio.Column():
405
- with gradio.Group():
406
- Base64Input = gradio.Textbox(label='Text for Base64 📦', placeholder='Enter text to encode/decode', lines=3)
407
- Base64Choice = gradio.Radio(label='Operation 🔄', choices=['encode', 'decode'], value='encode', interactive=True)
408
- Base64Output = gradio.Text(label='Base64 Result 📦', interactive=False)
409
- Base64Btn = gradio.Button('Process Base64 📦', variant='primary')
410
- Base64Btn.click(Base64, inputs=[Base64Input, Base64Choice], outputs=Base64Output)
411
-
412
- with gradio.Group():
413
- HashInput = gradio.Textbox(label='Text to Hash 🔐', placeholder='Enter text to hash', lines=3)
414
- HashChoice = gradio.Radio(label='Hashing Algorithm 🔄', choices=['md5', 'sha1', 'sha256'], value='md5', interactive=True)
415
- HashOutput = gradio.Text(label='Hash Result 🔐', interactive=False)
416
- HashBtn = gradio.Button('Generate Hash 🔐', variant='primary')
417
- HashBtn.click(Hash, inputs=[HashInput, HashChoice], outputs=HashOutput)
418
-
419
- with gradio.TabItem('Memory Tools 💾'):
420
- with gradio.Row():
421
- with gradio.Column():
422
- MemoryPasswordInput = gradio.Textbox(label='Password 🔐', placeholder='Enter memory password', type='password', lines=1)
423
- with gradio.Group():
424
- SaveInput = gradio.Textbox(label='Memory Text 💭', placeholder='Enter text to save', lines=3)
425
- SaveBtn = gradio.Button('Save Memory 💾', variant='primary')
426
- SaveBtn.click(SaveMemory, inputs=[SaveInput, MemoryPasswordInput], outputs=gradio.Text(label='Result'))
427
-
428
- with gradio.Group():
429
- DeleteInput = gradio.Textbox(label='Memory ID 🗑️', placeholder='Enter ObjectId to delete', lines=1)
430
- DeleteBtn = gradio.Button('Delete Memory 🗑️', variant='secondary')
431
- DeleteBtn.click(DeleteMemory, inputs=[DeleteInput, MemoryPasswordInput], outputs=gradio.Text(label='Result'))
432
-
433
- with gradio.Column():
434
- with gradio.Group():
435
- ListBtn = gradio.Button('List All Memories 📄', variant='primary')
436
- ListBtn.click(ListMemories, inputs=MemoryPasswordInput, outputs=gradio.Text(label='Memories'))
437
-
438
- with gradio.Group():
439
- SearchInput = gradio.Textbox(label='Search Query 🔍', placeholder='Enter search text', lines=1)
440
- SearchBtn = gradio.Button('Search Memories 🔎', variant='primary')
441
- SearchBtn.click(SearchMemories, inputs=[SearchInput, MemoryPasswordInput], outputs=gradio.Text(label='Results'))
 
 
 
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