Monday, August 28, 2023

Using ChatGPT with Python GUI


# API Key created on 28th August, 2023, valid for 3 months

# Email: bt25.bcrs@gmail.com Password: Bantuda25New

# Verification Mobile: 9847578833

# https://copyassignment.com/create-your-own-chatgpt-with-python/


import openai

from tkinter import *


win = Tk()

win.geometry("750x450")

win['background'] = '#11A37B'

win.title("Using ChatGPT with Python GUI")


openai.api_key = "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"

model_engine = "text-davinci-003"


def reply(e):

  completion = openai.Completion.create(n=1, stop=None,

  engine="text-davinci-003", prompt=S1.get(),

  max_tokens=1024, temperature=0.5)

  response = completion.choices[0].text.strip()

  txt.delete("0.0", END)

  txt.insert("1.0", response)


S1, S2 = StringVar(), StringVar()

S1.set("")

font1 = ("Verdana", 14, "bold")

font2 = ("Verdana", 24, "bold")

lblHeader = Label(win, text="Hosted by BCRS", font=font2, bg='#11A37B', fg='#FFFFFF')

lblHeader.place(x=280, y=25)

pic = PhotoImage(file="ChatGPT.png")

lblImg = Label(win, image=pic)

lblImg.place(x=40, y=5)

lbl = Label(win, text='Enter prompt', font=font1, bg='#11A37B', fg='#FFFFFF')

lbl.place(x=10, y=130)

ent = Entry(win, textvariable=S1, font=font1, width=40, bg='#11A37B', fg='#FFFFFF')

ent.place(x=180, y=130)

ent.bind('<Return>', reply)

ent.focus()

txt = Text(win, font=font1, width=50, height=10, wrap=WORD, bg='#11A37B', fg='#FFFFFF')

txt.place(x=25, y=180)


win.mainloop()


Use ChatGPT with Python

# API Key created on 28th August, 2023, valid for 3 months

# Email: bt25.bcrs@gmail.com Password: Bantuda25New

# Verification Mobile: 9847578833

# https://copyassignment.com/create-your-own-chatgpt-with-python/


import openai


openai.api_key = "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"


while True:

  model_engine = "text-davinci-003"

  prompt = input('Enter new prompt: ')


  if 'exit' in prompt or 'quit' in prompt:

    break


  completion = openai.Completion.create(

    engine=model_engine, prompt=prompt,

    max_tokens=1024, n=1, stop=None,

    temperature=0.5,

  )


  response = completion.choices[0].text

  print(response)


Tuesday, August 15, 2023

Python script to backup files

import shutil

inn = open("C:/Users/TECHNOSOFT/Desktop/Files to Backup.txt")
L = inn.readlines()
L1 = []
for src in L:
  src = src.strip()
  dest = "G" + src[1:]
  shutil.copy(src, dest)
inn.close()

Saturday, August 5, 2023

Calculating percentiles of marks (roughly as per CBSE guidelines)

import random, csv


nos = 135

nop = 8

percentile = nos // nop

grades = ["A+", "A", "B+", "B", "C+", "C", "D", "F",]


def WriteCSV():

  out = open("Marks.csv", 'w', newline='')

  W = csv.writer(out)

  W.writerow(["English", "Maths"])

  for i in range(nos):

    E = random.randint(30, 100)

    M = random.randint(30, 100)

    W.writerow([E, M])

  out.close()


def ReadCSV():

  inn = open("Marks.csv", 'r', newline='')

  R = csv.reader(inn)

  L = list(R)

  eMarks, mMarks = [], []

  eCutOffs, mCutOffs = [], []

  for i in range(1, len(L)):

    eMarks.append(int(L[i][0]))

    mMarks.append(int(L[i][1]))

  eMarks.sort(reverse=True)

  mMarks.sort(reverse=True)

  for i in range(0, len(eMarks), percentile):

    print(eMarks[i:i+percentile])

    if i < nop * percentile:

      eCutOffs.append(eMarks[i+percentile])

  print(eCutOffs)

  for i in range(1, len(L)):

    for j in range(len(eCutOffs)):

      if int(L[i][0]) >= eCutOffs[j]:

        grade = grades[j]

    L[i].insert(1, grade)

  print(L)


  out = open("Grades.xlsx", 'w', newline='')

  W = csv.writer(out)

  W.writerows(L)

  out.close()


WriteCSV()

ReadCSV()