Skip to content

a simple graphical user interface (GUI) application that interacts with the ChatGPT API. The application is built using Python and the Tkinter library. Users can input their questions, and the application will display the responses generated by the AI

Notifications You must be signed in to change notification settings

JeninSutradhar/GPT-Chatbot-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

ChatGPT Application

This repository contains a simple graphical user interface (GUI) application that interacts with the ChatGPT API. The application is built using Python and the Tkinter library. Users can input their questions, and the application will display the responses generated by the AI.

Features

  • Simple and intuitive GUI
  • Interaction with ChatGPT API to get answers
  • Easy to use: Type a question and get an answer

image

Prerequisites

  • Python 3.x
  • requests library

Installation

Clone the repository:

git clone https://github.com/yourusername/ChatGPT-Application.git
cd ChatGPT-Application
  • Install the required dependencies:
pip install requests

Usage

Run the application:

python gpt_app.py
  • In the GUI window, type your question in the text box and click the "Send" button. The answer will be displayed below.

  • To exit the application, type exit and click the "Send" button, or click the "Exit" button.

Code Overview

  • gpt_app.py

  • This is the main file that contains the following functions and GUI setup:

  • chat_with_ai(question): Sends a GET request to the ChatGPT API with the provided question and returns the AI's response or an error message.

  • send_question(): Handles the process of sending the user's question to the AI and displaying the answer in the GUI.

  • create_gui(): Sets up the Tkinter GUI with input fields, buttons, and response display area.

Example

import tkinter as tk
from tkinter import Text, Button, END
import requests

def chat_with_ai(question):
    api_url = "https://chatgpt.apinepdev.workers.dev/?question="
    full_url = api_url + question
    response = requests.get(full_url)
    if response.status_code == 200:
        data = response.json()
        return data.get("answer", "No answer available.")
    else:
        return "Error: " + str(response.status_code)

def send_question():
    question = question_entry.get("1.0", END).strip()
    if question.lower() == 'exit':
        window.destroy()
    else:
        answer = chat_with_ai(question)
        answer_text.configure(state="normal")
        answer_text.insert(END, "Answer: " + answer + "\n\n", "answer")
        answer_text.configure(state="disabled")
        question_entry.delete("1.0", END)
        question_entry.focus()

def create_gui():
    global window
    window = tk.Tk()
    window.title("ChatGPT")
    window.configure(bg="gray")
    window.geometry("600x800")

    prompt_label = tk.Label(window, text="Ask me anything!", font=("Helvetica", 20), bg="gray", fg="black")
    prompt_label.pack(pady=10)

    global question_entry
    question_entry = Text(window, width=40, height=3, bg="darkgray", fg="black")
    question_entry.pack(pady=10)

    global answer_text
    answer_text = Text(window, width=80, height=30, bg="black", fg="green")
    answer_text.tag_configure("answer", foreground="white")
    answer_text.configure(state="disabled")
    answer_text.pack(pady=10)

    send_button = Button(window, text="Send", command=send_question, bg="gray", fg="black")
    send_button.pack(side=tk.RIGHT, padx=10, pady=10)

    exit_button = Button(window, text="Exit", command=window.destroy, bg="gray", fg="black")
    exit_button.pack(side=tk.RIGHT, padx=10, pady=10)

    window.mainloop()

if __name__ == "__main__":
    create_gui()

License

  • This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • The application uses the ChatGPT API provided by OpenAI.
  • The GUI is built using the Tkinter library.
  • Feel free to contribute to the project by opening issues or submitting pull requests. Enjoy chatting with AI!

About

a simple graphical user interface (GUI) application that interacts with the ChatGPT API. The application is built using Python and the Tkinter library. Users can input their questions, and the application will display the responses generated by the AI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages