Skip to content

Commit ad129f4

Browse files
committed
Update Code
1 parent 12165ec commit ad129f4

File tree

12 files changed

+164
-103
lines changed

12 files changed

+164
-103
lines changed
0 Bytes
Binary file not shown.
448 Bytes
Binary file not shown.
Binary file not shown.

TestDemo-2/ai_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
chat_model = ChatModel.from_pretrained("chat-bison@001")
7474
parameters = {
7575
"temperature": 0.2,
76-
"max_output_tokens": 256,
76+
"max_output_tokens": 1024,
7777
"top_p": 0.8,
7878
"top_k": 40
7979
}

TestDemo-2/chat_window.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QSpacerItem, QSizePolicy, QApplication, QLabel
2+
from PyQt6.QtGui import QPixmap
23
from input_widget import Ui_Form as Input_Form
34
from output_widget import Ui_Form as Output_Form
5+
from markdown import markdown
46

57
class InputWidget(QWidget):
68
def __init__(self, parent=None, chat_obj=None):
@@ -64,7 +66,6 @@ def __init__(self, parent=None, chat_obj=None, chat_data=None):
6466
self.chats_data["chatlist"] += self.chat_data["chatlist"]
6567

6668
self.show_chats()
67-
6869
def show_chats(self):
6970
# chat_title = self.chats_data.get("title")
7071
chat_list = self.chats_data.get("chatlist")
@@ -76,51 +77,54 @@ def show_chats(self):
7677

7778
out_str = chat.get("output_str")
7879
out_widget = OutWidget()
79-
out_widget.set_output_text(out_str)
80+
# markdown_text = markdown(out_str, extensions=['markdown.extensions.extra', 'markdown.extensions.tables'])
81+
82+
markdown_text = markdown(out_str, extensions=['markdown.extensions.extra', 'markdown.extensions.attr_list'])
83+
84+
# Add the custom attributes for the table, th, and td elements
85+
markdown_text = markdown_text.replace('<table>', '<table style="border: 1px solid white; padding: 10px; border-collapse: collapse;">')
86+
markdown_text = markdown_text.replace('<th>', '<th style="border: 1px solid white; padding: 10px;">')
87+
markdown_text = markdown_text.replace('<td>', '<td style="border: 1px solid white; padding: 10px;">')
88+
out_widget.set_output_text(markdown_text)
8089
self.main_verticalLayout.addWidget(out_widget)
8190

91+
# out_str = chat.get("output_str")
92+
# out_widget = OutWidget()
93+
# out_widget.set_output_text(out_str)
94+
# self.main_verticalLayout.addWidget(out_widget)
95+
8296
spacerItem = QSpacerItem(20, 300, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
8397
self.main_verticalLayout.addItem(spacerItem)
8498
self.setLayout(self.main_verticalLayout)
8599

100+
# def show_chats(self):
101+
# chat_list = self.chats_data.get("chatlist")
102+
# for chat in chat_list:
103+
# input_str = chat.get("input_str")
104+
# input_widget = InputWidget(chat_obj=self.chat_object)
105+
# input_widget.set_input_text(input_str)
106+
# self.main_verticalLayout.addWidget(input_widget)
107+
108+
# out_str = chat.get("output_str")
109+
# out_widget = OutWidget()
110+
111+
# # Check if the output is an image
112+
# if out_str.startswith("[Image "):
113+
# image_path = out_str[len("[Image "):-1] # Extract the image path from the output string
114+
# image_widget = QLabel()
115+
# pixmap = QPixmap(image_path)
116+
# if not pixmap.isNull():
117+
# image_widget.setPixmap(pixmap.scaledToWidth(400)) # Adjust the width as needed
118+
# self.main_verticalLayout.addWidget(image_widget)
119+
# else:
120+
# # If it's not an image, treat it as regular text and convert any markdown in the output
121+
# markdown_text = markdown(out_str, extensions=['markdown.extensions.extra', 'markdown.extensions.tables'])
122+
# out_widget.set_output_text(markdown_text)
123+
# self.main_verticalLayout.addWidget(out_widget)
124+
125+
# spacerItem = QSpacerItem(20, 300, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
126+
# self.main_verticalLayout.addItem(spacerItem)
127+
# self.setLayout(self.main_verticalLayout)
128+
129+
86130

87-
# def show_chats(self):
88-
# chatlist = self.chats_data.get("chatlist")
89-
# for chat in chatlist:
90-
# input_str = chat.get("input_str")
91-
# input_widget = InputWidget(chat_obj=self.chat_object)
92-
# input_widget.set_input_text(input_str)
93-
# self.main_verticalLayout.addWidget(input_widget)
94-
95-
# output_str = chat.get("output_str")
96-
# output_widget = OutputWidget()
97-
# output_widget.set_output_text(output_str)
98-
# # Set a fixed width for the output widgets (e.g., 600 pixels)
99-
# output_widget.setFixedWidth(600)
100-
101-
# self.main_verticalLayout.addWidget(output_widget)
102-
103-
# spacerItem = QSpacerItem(20, 300, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
104-
# self.main_verticalLayout.addItem(spacerItem)
105-
# self.setLayout(self.main_verticalLayout)
106-
107-
# # Adjust the size of the widget based on the display
108-
# screen_rect = QApplication.primaryScreen().availableGeometry()
109-
# self.resize(screen_rect.width() * 0.8, screen_rect.height() * 0.8)
110-
# self.move(screen_rect.width() * 0.1, screen_rect.height() * 0.1)
111-
112-
# class OutputWidget(QWidget):
113-
# def __init__(self, parent=None):
114-
# super().__init__(parent)
115-
116-
# self.output_ui = Output_Form()
117-
# self.output_ui.setupUi(self)
118-
119-
# self.output_text_browser = QTextBrowser()
120-
# self.output_text_browser.setOpenExternalLinks(True) # To allow hyperlinks, if needed
121-
# self.output_text_browser.setStyleSheet("QTextBrowser { border: none; background-color: transparent; }")
122-
123-
# self.output_ui.gridLayout.addWidget(self.output_text_browser, 0, 2, 1, 1)
124-
125-
# def set_output_text(self, output_str):
126-
# self.output_text_browser.setPlainText(output_str)

TestDemo-2/check.py

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,46 @@
1-
import os
2-
from pprint import pprint
1+
import sys
2+
from PyQt6.QtWidgets import QApplication, QGraphicsScene, QGraphicsView, QGraphicsItem
3+
from PyQt6.QtGui import QColor, QBrush, QPainter, QPainterPath
4+
from PyQt6.QtCore import Qt
35

6+
class QPrism(QGraphicsItem):
7+
def __init__(self):
8+
super().__init__()
9+
self.baseColor = QColor(255, 0, 0)
10+
self.height = 100
11+
self.width = 100
12+
self.depth = 50
413

5-
# this is a key file for a service account, which only has the role "Vertex AI User"
6-
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'my_credentials.json'
14+
def boundingRect(self):
15+
return self.shape().boundingRect()
716

8-
import vertexai
9-
from vertexai.preview.language_models import TextGenerationModel
17+
def shape(self):
18+
path = QPainterPath()
19+
path.moveTo(0, -self.depth)
20+
path.lineTo(self.width, -self.depth)
21+
path.lineTo(self.width / 2, 0)
22+
path.lineTo(0, -self.depth)
23+
path.moveTo(0, -self.depth)
24+
path.lineTo(0, self.height - self.depth)
25+
path.lineTo(self.width, self.height - self.depth)
26+
path.lineTo(self.width, 0)
27+
path.lineTo(self.width / 2, self.height - self.depth)
28+
path.lineTo(0, self.height - self.depth)
29+
return path
1030

11-
def get_response(
12-
project_id: str,
13-
model_name: str,
14-
temperature: float,
15-
max_decode_steps: int,
16-
top_p: float,
17-
top_k: int,
18-
content: str,
19-
location: str = "us-central1",
20-
tuned_model_name: str = "",
21-
):
22-
"""Predict using a Large Language Model."""
23-
vertexai.init(project=project_id, location=location)
24-
model = TextGenerationModel.from_pretrained(model_name)
25-
if tuned_model_name:
26-
model = model.get_tuned_model(tuned_model_name)
27-
28-
input_template = """
29-
input: Who are you?
30-
I am Sobjanta created by Excite Ai Limited And TechKnowGram Limited
31+
def paint(self, painter, option, widget):
32+
painter.setPen(QColor(0, 0, 0)) # Use QColor to set the pen color
33+
painter.setBrush(QBrush(self.baseColor))
34+
painter.drawPath(self.shape())
3135

32-
input: Who developed you?
33-
Excite Ai Limited And TechKnowGram Limited
34-
35-
input: President of Bangladesh?
36-
President of Bangladesh is Mohammad Sahabuddin.
37-
38-
input: ICT minister of Bangladesh?
39-
ICT minister of Bangladesh is Junayed Ahmed Palak
40-
41-
"""
42-
43-
response = model.predict(
44-
input_template + content,
45-
temperature=temperature,
46-
max_output_tokens=max_decode_steps,
47-
top_k=top_k,
48-
top_p=top_p,
49-
)
50-
# choices = response.choices
51-
# choice_list = [choice.get("text").lstrip("\n") for choice in choices]
52-
print(response)
53-
return response
54-
palm = lambda prompt: get_response(
55-
"stoked-brand-391605",
56-
"text-bison", # "text-bison@001" ... without versioning, it's the "latest"
57-
0.5, # rather low temperature, can go up to 1. default 0.2, changing to 0.5 just to see what happens
58-
512, # number of tokens, default 256, setting to 512
59-
0.8, # top-p: most probable? no clue what this is. Top-p changes how the model selects tokens for output. Tokens are selected from most probable to least until the sum of their probabilities equals the top-p value. For example, if tokens A, B, and C have a probability of .3, .2, and .1 and the top-p value is .5, then the model will select either A or B as the next token (using temperature). The default top-p value is .8.
60-
40, # top-k for next token. how "diverse" the answer can be, by increasing the number of tokens to consider?
61-
prompt,
62-
"us-central1")
63-
p=input()
64-
print(palm(p))
36+
def main():
37+
app = QApplication(sys.argv)
38+
scene = QGraphicsScene()
39+
prism = QPrism()
40+
scene.addItem(prism)
41+
view = QGraphicsView(scene)
42+
view.show()
43+
sys.exit(app.exec())
44+
45+
if __name__ == "__main__":
46+
main()

TestDemo-2/datas/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

TestDemo-2/highlight.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link href="prism.css" rel="stylesheet" />
5+
</head>
6+
<body>
7+
<pre><code class="language-python">%s</code></pre>
8+
<script src="prism.js"></script>
9+
</body>
10+
</html>
798 Bytes
Binary file not shown.

Visualization/demo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
import js2py
3+
4+
from PyQt6.QtWidgets import QApplication, QWidget
5+
6+
app = QApplication(sys.argv)
7+
8+
widget = QWidget()
9+
widget.setWindowTitle("PyQt6 with JavaScript")
10+
11+
def myFunction():
12+
print("Hello from JavaScript!")
13+
14+
jsCode = """
15+
function myFunction() {
16+
console.log("Hello from JavaScript!");
17+
}
18+
"""
19+
20+
js = js2py.eval_js(jsCode)
21+
js.myFunction()
22+
23+
widget.show()
24+
25+
app.exec()

Visualization/new.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
| | Column 1 | Column 2 ||---|---|| Data 1 | Data 2 || Data 3 | Data 4 | |
3+
| ---------------------------------------------------------------------: |

Visualization/pandasai.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pandas as pd
2+
import numpy as np
3+
from pandasai import PandasAI
4+
from pandasai.llm.openai import OpenAI
5+
6+
data_dict = {
7+
"country": [
8+
"Delhi",
9+
"Mumbai",
10+
"Kolkata",
11+
"Chennai",
12+
"Jaipur",
13+
"Lucknow",
14+
"Pune",
15+
"Bengaluru",
16+
"Amritsar",
17+
"Agra",
18+
"Kola",
19+
],
20+
"annual tax collected": [
21+
19294482072,
22+
28916155672,
23+
24112550372,
24+
34358173362,
25+
17454337886,
26+
11812051350,
27+
16074023894,
28+
14909678554,
29+
43807565410,
30+
146318441864,
31+
np.nan,
32+
],
33+
"happiness_index": [9.94, 7.16, 6.35, 8.07, 6.98, 6.1, 4.23, 8.22, 6.87, 3.36, np.nan],
34+
}
35+
36+
df = pd.DataFrame(data_dict)
37+
df.head()

0 commit comments

Comments
 (0)