Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,44 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +93,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
# ==============================================
|
| 37 |
+
# YOUR TEXT COUNTER TOOL - ADD THIS WHOLE BLOCK
|
| 38 |
+
# ==============================================
|
| 39 |
+
@tool
|
| 40 |
+
def count_text_stats(text: str) -> str:
|
| 41 |
+
"""Count characters, words, and sentences in a text.
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
text: The text you want to analyze
|
| 45 |
+
"""
|
| 46 |
+
# Count characters (including spaces)
|
| 47 |
+
char_count = len(text)
|
| 48 |
+
|
| 49 |
+
# Count words (split by spaces)
|
| 50 |
+
words = text.split()
|
| 51 |
+
word_count = len(words)
|
| 52 |
+
|
| 53 |
+
# Handle empty text to avoid division by zero
|
| 54 |
+
if word_count == 0:
|
| 55 |
+
return f"""📊 Text Statistics:
|
| 56 |
+
- Characters: {char_count}
|
| 57 |
+
- Words: 0
|
| 58 |
+
- Sentences: 0
|
| 59 |
+
- Average word length: 0 characters"""
|
| 60 |
+
|
| 61 |
+
# Count sentences (split by ., !, ?)
|
| 62 |
+
sentence_endings = ['.', '!', '?']
|
| 63 |
+
sentence_count = 0
|
| 64 |
+
for char in text:
|
| 65 |
+
if char in sentence_endings:
|
| 66 |
+
sentence_count += 1
|
| 67 |
+
|
| 68 |
+
return f"""📊 Text Statistics:
|
| 69 |
+
- Characters: {char_count}
|
| 70 |
+
- Words: {word_count}
|
| 71 |
+
- Sentences: {sentence_count}
|
| 72 |
+
- Average word length: {char_count / word_count:.1f} characters"""
|
| 73 |
+
# ==============================================
|
| 74 |
|
| 75 |
final_answer = FinalAnswerTool()
|
| 76 |
|
|
|
|
| 93 |
|
| 94 |
agent = CodeAgent(
|
| 95 |
model=model,
|
| 96 |
+
tools=[final_answer, count_text_stats], # <-- ADDED count_text_stats HERE!
|
| 97 |
max_steps=6,
|
| 98 |
verbosity_level=1,
|
| 99 |
grammar=None,
|