sarim commited on
Commit
f2fb591
·
1 Parent(s): 8cd3882
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -30,10 +30,20 @@ model = GroqModel('llama-3.1-70b-versatile', api_key = api_key)
30
 
31
 
32
 
33
- def split_long_string(long_string, chunk_size=3500):
34
- string_data = "".join(long_string)
35
- words = string_data.split()
36
- chunks = [' '.join(words[i:i + chunk_size]) for i in range(0, len(words), chunk_size)]
 
 
 
 
 
 
 
 
 
 
37
 
38
  return chunks
39
 
@@ -68,7 +78,8 @@ async def ppt_content(data):
68
  "3. Bullet point: A list of bullet points summarizing key information on the slide. Each bullet point should be detail, long, and highlight a specific aspect of the slide's topic. ideally, limit to 3-5 points.",
69
  "4. Image Suggestion: A prompt for generating an image to complement the slide content. Describe the desired visual in detail, including elements, style, and relevance to the topic. Ensure the prompt is actionable for AI tools.",
70
  ))
71
- # listOfString = split_long_string(data)
 
72
  # for i, chunk in enumerate(listOfString):
73
  # print(f"Chunk {i}:\n{chunk}\n")
74
 
@@ -78,7 +89,7 @@ async def ppt_content(data):
78
 
79
 
80
  deps :SupportDependencies = SupportDependencies(db="".join(data))
81
- result_1 = agent.run_sync(user_prompt = f"Create me a powerpoint presentation from {deps.db}",deps=deps)
82
  #print(result_1.data)
83
  print(result_1)
84
 
 
30
 
31
 
32
 
33
+
34
+ def split_into_token_chunks(text: str, max_tokens: int = 6000) -> list:
35
+ """
36
+ Splits a long string into chunks of a specified maximum number of tokens (words).
37
+
38
+ :param text: The input string to split.
39
+ :param max_tokens: The maximum number of tokens (words) per chunk.
40
+ :return: A list of strings, each containing up to `max_tokens` tokens.
41
+ """
42
+ # Split the text into words (tokens)
43
+ tokens = text.split()
44
+
45
+ # Create chunks of words
46
+ chunks = [' '.join(tokens[i:i + max_tokens]) for i in range(0, len(tokens), max_tokens)]
47
 
48
  return chunks
49
 
 
78
  "3. Bullet point: A list of bullet points summarizing key information on the slide. Each bullet point should be detail, long, and highlight a specific aspect of the slide's topic. ideally, limit to 3-5 points.",
79
  "4. Image Suggestion: A prompt for generating an image to complement the slide content. Describe the desired visual in detail, including elements, style, and relevance to the topic. Ensure the prompt is actionable for AI tools.",
80
  ))
81
+ listOfString = split_into_token_chunks(data)
82
+ print(len(listOfString))
83
  # for i, chunk in enumerate(listOfString):
84
  # print(f"Chunk {i}:\n{chunk}\n")
85
 
 
89
 
90
 
91
  deps :SupportDependencies = SupportDependencies(db="".join(data))
92
+ result_1 = agent.run_sync(user_prompt = f"Create me a powerpoint presentation",deps=deps)
93
  #print(result_1.data)
94
  print(result_1)
95