tonic commited on
Commit
c44ba13
1 Parent(s): 147203c

adding some pattern recognition for displaying some interesting things for learning activity

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -11,6 +11,8 @@ import requests
11
  from io import BytesIO
12
  import cohere
13
  import os
 
 
14
 
15
  title = "# Welcome to AyaTonic"
16
  description = "Learn a New Language With Aya"
@@ -20,6 +22,47 @@ load_dotenv()
20
  COHERE_API_KEY = os.getenv('CO_API_KEY')
21
  SEAMLESSM4T = os.getenv('SEAMLESSM4T')
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  co = cohere.Client(COHERE_API_KEY)
24
  audio_client = Client(SEAMLESSM4T)
25
 
 
11
  from io import BytesIO
12
  import cohere
13
  import os
14
+ import re
15
+
16
 
17
  title = "# Welcome to AyaTonic"
18
  description = "Learn a New Language With Aya"
 
22
  COHERE_API_KEY = os.getenv('CO_API_KEY')
23
  SEAMLESSM4T = os.getenv('SEAMLESSM4T')
24
 
25
+
26
+ # Regular expression patterns for each color
27
+ patterns = {
28
+ "red": r'<span style="color: red;">(.*?)</span>',
29
+ "blue": r'<span style="color: blue;">(.*?)</span>',
30
+ "green": r'<span style="color: green;">(.*?)</span>',
31
+ }
32
+
33
+ # Dictionaries to hold the matches
34
+ matches = {
35
+ "red": [],
36
+ "blue": [],
37
+ "green": [],
38
+ }
39
+ class TaggedPhraseExtractor:
40
+ def __init__(self, text=''):
41
+ self.text = text
42
+ self.patterns = {}
43
+
44
+ def set_text(self, text):
45
+ """Set the text to search within."""
46
+ self.text = text
47
+
48
+ def add_pattern(self, color, pattern):
49
+ """Add a new color and its associated pattern."""
50
+ self.patterns[color] = pattern
51
+
52
+ def extract_phrases(self):
53
+ """Extract phrases for all colors and patterns added."""
54
+ matches = {color: re.findall(pattern, self.text) for color, pattern in self.patterns.items()}
55
+ return matches
56
+
57
+ def print_phrases(self):
58
+ """Extract phrases and print them."""
59
+ matches = self.extract_phrases()
60
+ for color, phrases in matches.items():
61
+ print(f"Phrases with color {color}:")
62
+ for phrase in phrases:
63
+ print(f"- {phrase}")
64
+ print()
65
+
66
  co = cohere.Client(COHERE_API_KEY)
67
  audio_client = Client(SEAMLESSM4T)
68