CineAI commited on
Commit
15b4974
·
verified ·
1 Parent(s): 7b3c9be

Create rainbolt_parody.py

Browse files
Files changed (1) hide show
  1. src/rainbolt_parody.py +53 -0
src/rainbolt_parody.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from io import BytesIO
3
+ from typing import Tuple, Dict, Any
4
+
5
+ from PIL import Image
6
+ from google import genai
7
+ from rich.console import Console
8
+ from rich.table import Table
9
+
10
+ console = Console()
11
+
12
+ class RainboltParody:
13
+ def __init__(self, title: str, api_key: str):
14
+ self.title = title
15
+ self.api_key = api_key
16
+
17
+ def get_info(self, SYSTEM_PROMPT: str, img: Any) -> Tuple[Dict[str, str], str, str]:
18
+ try:
19
+ client = genai.Client(api_key=self.api_key)
20
+
21
+ response = client.models.generate_content(
22
+ model="gemini-2.5-flash",
23
+ contents=[SYSTEM_PROMPT, img]
24
+ )
25
+
26
+ if (response.text != "" or response.text is not None) and type(response.text) == str:
27
+ clean_text = response.text.strip().replace('```json', '').replace('```', '')
28
+ return json.loads(clean_text), response.usage_metadata.thoughts_token_count, response.usage_metadata.total_token_count
29
+
30
+ except Exception as e:
31
+ print(f"Unfortunately happened an error: {e}")
32
+
33
+ def pretty_print_data(self, data: Dict[str, str]) -> None:
34
+ if not data:
35
+ print("No data to display.")
36
+ return
37
+
38
+ table = Table(
39
+ title=f"[bold dark_green]{self.title}[/bold dark_green]",
40
+ show_header=True,
41
+ header_style="bold magenta",
42
+ border_style="blue"
43
+ )
44
+
45
+ table.add_column("Attribute", style="cyan", no_wrap=True, justify="right")
46
+ table.add_column("Value", style="white")
47
+
48
+ for key, value in data.items():
49
+ if key == "confidence_score":
50
+ table.add_row(key, f"[bold yellow]{value}%[/bold yellow]")
51
+ else:
52
+ table.add_row(key, f"[bold yellow]{value}[/bold yellow]")
53
+ console.print(table)