[go: up one dir, main page]

0% found this document useful (0 votes)
20 views44 pages

NIPUNNNNN

This training report on Python, submitted by Chirayu Dashora for the Bachelor of Technology degree in Computer Science and Engineering, provides a comprehensive overview of the programming language, including its history, features, data types, and practical applications. The report highlights Python's simplicity, readability, and versatility in developing various applications, supported by detailed examples and explanations. Additionally, it covers the use of libraries like Tkinter for GUI development and Streamlit for web applications, showcasing Python's capabilities in both desktop and web environments.

Uploaded by

Nipun Somani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views44 pages

NIPUNNNNN

This training report on Python, submitted by Chirayu Dashora for the Bachelor of Technology degree in Computer Science and Engineering, provides a comprehensive overview of the programming language, including its history, features, data types, and practical applications. The report highlights Python's simplicity, readability, and versatility in developing various applications, supported by detailed examples and explanations. Additionally, it covers the use of libraries like Tkinter for GUI development and Streamlit for web applications, showcasing Python's capabilities in both desktop and web environments.

Uploaded by

Nipun Somani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 44

A

Training Report
On
“ PYTHON ”
Submitted in partial fulfillment of the requirement for the
Award of the degree of
Bachelor of Technology
In
Computer Science and Engineering
(Affiliated to Rajasthan Technical University, Kota)

(Academic Session 2023-24)

Submitted By:- Submitted To:-


Chirayu Dashora Mr. S. S. Saini
23EJECS028 HOD – CSE

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING JAIPUR


ENGINEERING COLLEGE, KUKAS JAIPURRAJASTHAN TECHNICAL
UNIVERSITY, KOTA
(AUGUST, 2024)
JAIPUR ENGINEERING COLLEGE
(Approved by AICTE, New Delhi & Affiliation to Rajasthan
Technical University, Kota Rajasthan)

INTERNAL GUIDE CERTIFICATE

This is to certify that Chirayu Dashora of B.Tech Computer Science Engineering


year (2023-27) at Jaipur Engineering College have completed the Major project report
entitled “PYTHON”. The project was completed in the 2nd-semester course and
partially fulfilled the requirements of Rajasthan Technical University, Kota.

The project report has been completed under the guidance of Ms. Chetana Pareta
(Ass. Professor, CSE Department) of JEC and is as per the norms and guidance
provided.

Ms. Chetana Pareta


(Assistant Professor)

Mr. S. S. Saini
(HOD CSE)

Sp-43 Ricco Industrial Area, Kukas, Jaipur (Rajasthan)


Phone No: 01426-511241/42/43 Fax: 01426-511240

www.jeckukas.org

ii
CERTIFICATE

iii
Candidate’s Declaration

“I hereby declare that the project work entitled “Python” submitted to Mr. Sultan Singh
Saini, is a record of an original work done by us under the guidance of Ms. Chetana
Pareta. This project has not been submitted earlier in part or full for the award of any
other degree or diploma of this or any other Institution/University to the best of our
knowledge and belief.
The report embodies the results of my own work and has been written by me. I
have not copied from any other students’ work or from any other sources except
where due reference acknowledgment is made explicitly in the text."

Chirayu Dashora

23EJECS028

iv
Acknowledgment

I would like to express my deepest appreciation to all those who provided me with the
possibility to complete my report. Furthermore, I would like to acknowledge with much
appreciation the crucial role of the other employees and teacher Ms. Chetana Pareta
who permitted me to use the required equipment and necessary materials to complete the
task. I sincerely acknowledge them for extending their valuable guidance, support for
literature, critical reviews of this report, and above all for the moral support they
provided me at all stages of the project. Last but certainly not least, I am deeply grateful
to my family for their unwavering love, support, and understanding throughout this
project. Their encouragement, understanding, and belief in our abilities have been
pivotal in my success. I would like to acknowledge that this project would not have been
possible without the collective efforts, contributions, and support of the organization.
Their involvement has truly made a significant impact on the successful completion of
this project.

v
Abstract

" This report provides an in-depth exploration of Python, beginning with its history and
evolution since its creation by Guido van Rossum in the late 1980s. It delves into the
basic constructs of the language, highlighting its simplicity and readability, which have
contributed to its widespread adoption. The report covers fundamental data types,
including integers, floats, strings, and lists, explaining their uses and operations. It
further discusses operators and control structures such as loops, demonstrating how they
facilitate efficient coding practices. The practical application of Python is showcased
through the Tkinter library, which enables the creation of graphical user interfaces
(GUIs), and Streamlit, a framework for developing interactive web applications. By
examining these libraries, the report illustrates Python's versatility in both desktop and
web development. Through detailed examples and explanations, readers will gain a solid
understanding of Python's basics and its powerful capabilities for building diverse
applications.

vi
TABLE OF CONTENT

TITLE PAGE i
APPROVAL AND INTERNAL GUIDE CERTIFICATE ii
CERTIFICATE iii
CANDIDATE’S DECLARATION iv
ACKNOWLEDGMENT v
ABSTRACT vi
TABLE OF CONTENTS vii - viii
LIST OF FIGURES ix
CONCLUSION 32
REFERENCE 33

S. No. Topic Page No.


1. Python 1-2
1.1 Introduction to Python 1
1.2 Features of Python 1
1.3 Releases of Python 3
1.4 Data Types of Python 3
1.5 Operators of Python 7
1.6 Python Comments 14
1.7 Indentation 15
2. Generative AI
2.1 About AI 3
2.2 Generative AI 3
2.3 Language Modeling 4
3. GUI 20
3.1 About GUI and Tkinter 20
3.2 Setting up Tkinter 20
3.3 Integrating Tkinter with Other Libraries 21
3.4 Creating a Simple GUI 22

vii
4. Hugging Face 23
4.1 Overview of Hugging Face in Python 23
4.2 Using Pre-Trained Models 24
4.3 Working with Specific Models 24
4.4 Popular Tasks 25
4.5 Using Datasets with Hugging Face 26
4.6 Model Hub 27
5. Project Undertaken 27
5.1 Text to Image Converter 27
5.2 Chatbot Application 29

viii
LIST OF FIGURES
S.No. Name of Figures Page No.
Fig 1.1 Sample List Code 4
Fig 1.2 Sample Dictionary Code 5
Fig 1.3 Sample Tuple Code 6
Fig 1.4 Sample Set Code 6
Fig 1.5 Sample String Code 7
Fig 1.6 Sample Data Type Code 7
Fig 1.7 Operators 8
Fig 1.8 Arithematic Operators 9
Fig 3.1 Code for Login Page 21
Fig 3.2 Output of Login Page 22
Fig 5.1 Code for TTI Generator 27
Fig 5.2 Output for TTI Generator 28
Fig 5.3 Code of Chatbot 30
Fig 5.4 Output of Chatbot 31

ix
x
Chapter – 1
PYTHON

1.1 Introduction to Python

Python is a widely used general-purpose, high level programming language. It was


initially designed by Guido van Rossum in 1991 and developed by Python Software
Foundation. It was mainly developed for emphasis on code readability, and its syntax
allows programmers to express concepts in fewer lines of code. Python is a programming
language that lets you work quickly and integrate systems more efficiently.

Python is a high-level, interpreted, interactive and object-oriented scripting language.


Python is designed to be highly readable. It uses English keywords frequently where as
other languages use punctuation, and it has fewer syntactical constructions than other
languages.

 Python is Interpreted − Python is processed at runtime by the interpreter. You do not


need to compile your program before executing it. This is similar to PERL and PHP.
 Python is Interactive − You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
 Python is Object-Oriented − Python supports Object-Oriented style or technique of
programming that encapsulates code within objects.
 Python is a Beginner's Language − Python is a great language for the beginner-level
programmers and supports the development of a wide range of applications from
simple text processing to WWW browsers to games.

1.2 PYTHON FEATURES

Python's features include –

 Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.

 Easy-to-read − Python code is more clearly defined and visible to the eyes.

1
 Easy-to-maintain − Python's source code is fairly easy-to-maintain.

 A broad standard library − Python's bulk of the library is very portable and cross-
platform compatible on UNIX, Windows, and Macintosh.

 Interactive Mode − Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.

 Portable − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.

 Extendable − You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.

 Databases − Python provides interfaces to all major commercial databases.

 GUI Programming − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.

 Scalable − Python provides a better structure and support for large programs than shell
scripting. Apart from the above-mentioned features, Python has a big list of good
features, few are listed below −

 It supports functional and structured programming methods as well as OOP.

 It can be used as a scripting language or can be compiled to byte-code for


building large applications.

 It provides very high-level dynamic data types and supports dynamic type
checking.

2
1.3 PYTHON RELEASES

Python 1.0 - January 1994

Python 1.5 - December 31, 1997

Python 1.6 - September 5, 2000 * Python 2.0 - October 16, 2000

Python 2.1 -April 17, 2001 &Python 2.2 - December 21, 2001 * Python 2.3 - July 29,
2003

Python 2.4 - November 30, 2004 * Python 2.5 -September 19, 2006 * Python 2.6 -
October 1, 2008

Python 2.7 - July 3, 2010

Python 3.0 - December 3, 2008 * Python 3.1 - June 27, 2009

Python 32. -February 20, 201

Python 3.3 -September 29, 2012 •Python 3.4 -March 16, 2014

Python 35. - September 13, 2015 Python 36. -December 23, 2016

1.4 DATA TYPES IN PYTHON

Data types determine whether an object can do something, or whether it just would not
make sense. Other programming languages often determine whether an operation makes
sense for an object by making sure the object can never be stored somewhere where the
operation will be performed on the object (this type system is called static typing). Python
does not do that. Instead, it stores the type of an object with the object and checks when
the operation is performed whether that operation makes sense for that object (this is
called dynamic typing).

Python has many native data types. Here are the important ones:
Booleans are either True or False.
Numbers can be integers 1( and 2), floats (1.1 and 1.2), fractions (1/2 and 2/3), or even
3
complex numbers.
Strings are sequences of Unicode characters, e.g. an HTML document.
Bytes and byte arrays, e.g. a JPEG image file.
Lists are ordered sequences of values.
Tuples are ordered, immutable sequences of values.
Sets are unordered bags of values.

1.4.1 LISTS-
• Ordered collection of data.
• Supports similar slicing and indexing functionalities as in the case of Strings.
• They are mutable.
• Advantage of a list over a conventional array
• Lists have no size or type constraints(no setting restrictions beforehand).
• They can contain different object types.

Figure 1.1 Sample List Code

1.4.2 DICTIONARY-

Lists are sequences but the dictionaries are mappings. They are mappings between a
unique key and a value pair. These mappings may not retain order.

It is enclosed by curly braces {} and values can be assigned and accessed using square
brackets[].

4
Figure 1.2 Sample Dictionary Code

1.4.3 TUPLES-

A Tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists.
The differences between tuples and lists are, the tuples cannot be changed unlike lists and
tuples use parentheses, whereas lists use square brackets.
Creating a tuple is as simple as putting different comma-separated values. Optionally you
can put these comma-separated values between parentheses also. For example –

tup1 =('physics', 'chemistry', 1997, 2000);


tup2 =(1,2, 3, 4, 5);
tup3 = “a”, “b”, “c”, “d”;

• Immutable in nature, i.e they cannot be changed.


• No type restriction
• We can use tuples to present things that shouldn't change, such as days of the week,
or dates on a calendar, etc.

Figure 1.3 Sample Tuple Code

5
1.4.4 SETS-

• A set contains unique and unordered elements and we can construct them by using a set)
function.
• Convert a list into Set-
• 1=[1,2,3,4,1,1,2,3,6,7) • =k set(i)
• k becomes (1,2,3,4,6,7) • Basic Syntax-
• x.add (1)
• x=(1)
• x.add(1)
• This would make no change in x now

Fig 1.4 Sample Set Code

1.4.5 STRING
In programming terms, we usually call text a string. When you think of a string as a
collection of letters, the term makes sense.
Al the letters, numbers, and symbols in this book could be a string.
For that matter, your name could be a string, and so could your address.

Fig 1.5 Sample String Code

6
1.4.6 NUMERIC DATA TYPES

Numbers have four types in Python. Int, float, complex, and long.

Fig 1.6 Sample Code

1.5 PYTHON OPERATORS

Operators are used to perform operations on variables and values.

Python divides the operators in the following groups:

 Arithmetic operators
 Assignment operators
 Comparison operators
 Logical operators
 Identity operators
 Membership operators
 Bitwise operators

7
Fig 1.7 Operators

1.5.1 ARITHEMATIC OPERATORS:

Python Arithmetic operators are used to perform basic mathematical operations


like addition, subtraction, multiplication, and division.
Example -

8
Fig 1.8 Arithmetic Operator

OUTPUT :

ASSIGNMENT OPERATORS :

The Assignment operator is one of the most frequently used operators in Python. The
operator consists of a single equal sign (=), and it operates on two operands. The left-hand
operand is typically a variable, while the right-hand operand is an expression.

COMPARISION OPERATORS:
9
The Python comparison operators allow you to compare numerical values and any other
objects that support them. The table below lists all the currently available comparison
operators in Python:

LOGICAL OPERATORS:

Python logical operators are used to combine conditional statements, allowing you to
perform operations based on multiple conditions. These Python Operators, alongside
arithmetic operators, are special symbols used to carry out computations on values and
variables. In this article, we will discuss logical operators in Python definition and also
look at some Python logical operators programs, to completely grasp the concept.

10
IDENTITY OPERATORS:

Identity operators are used to compare the objects, not if they are equal, but if they are the
same object, with the same memory location:

TYPES OF IDENTITY OPERATORS:


 is
 is not

11
MEMBERSHIP OPERATORS:

The Python membership operators test for the membership of an object in a sequence,
such as strings, lists, or tuples. Python offers two membership operators to check or
validate the membership of a value. They are as follows:

Membership Operator Description Syntax


in Operator Returns true if the value Value in sequence
exists in a sequence , else
returns false
not in Operator Returns false if the value Value not in sequence
exists in a sequence else
returns true

IN OPERATOR :
The in operator is used to check if a character/substring/element exists in a
sequence or not. Evaluate to True if it finds the specified element in a sequence
otherwise False.

NOT IN OPERATOR :
The not in Python operator evaluates to true if it does not find the variable in the
specified sequence and false otherwise.

BITWISE OPERATORS:

Bitwise operators are employed in python to perform bitwise operations on numbers. The
values are first converted to binary, and then manipulations are done bit by bit, hence the
phrase "bitwise operators." The outcome is then displayed in decimal numbers.

12
Bitwise Logical Operator: These operators are employed to execute logical operations
like other logical operators bit by bit. This is akin to using logical operators such as and,
or, and not on a bit level. Except for these basic facts, bitwise and logical operators are
analogous.

Bitwise Shift Operators: These operators multiply or divide an integer number by two by
shifting every individual bit to the left or right. We can use them when we wish to
multiply or divide a value by a power of 2. Python's bitwise operators only work with
integers.

1.6 PYTHON COMMENTS:

We may wish to describe the code we develop. We might wish to take notes of why a
section of script functions, for instance. We leverage the remarks to accomplish this.
Formulas, procedures, and sophisticated business logic are typically explained with
comments. The Python interpreter overlooks the remarks and solely interprets the script
when running a program. Single-line comments, multi-line comments, and documentation
strings are the 3 types of comments in Python.

Advantages of Using Comments

Our code is more comprehensible when we use comments in it. It assists us in recalling
why specific sections of code were created by making the program more understandable.

Aside from that, we can leverage comments to overlook specific code while evaluating
other code sections. This simple technique stops some lines from running or creates a fast
pseudo-code for the program.

Types of Comments in Python

In Python, there are 3 types of comments. They are described below:

Single-Line Comments

Single-line remarks in Python have shown to be effective for providing quick descriptions
for parameters, function definitions, and expressions. A single-line comment of Python is
the one that has a hashtag # at the beginning of it and continues until the finish of the line.
13
If the comment continues to the next line, add a hashtag to the subsequent line and
resume the conversation.

Multi-Line Comments

Python does not provide the facility for multi-line comments. However, there are indeed
many ways to create multi-line comments.

With Multiple Hashtags (#)

In Python, we may use hashtags (#) multiple times to construct multiple lines of
comments. Every line with a (#) before it will be regarded as a single-line comment.

Python If-else statements

Decision making is the most important aspect of almost all the programming languages.
As the name implies, decision making allows us to run a particular block of code for a
particular decision. Here, the decisions are made on the validity of the particular
conditions. Condition checking is the backbone of decision making.

1.7 Indentation in Python

For the ease of programming and to achieve simplicity, python doesn't allow the use of
parentheses for the block level code. In Python, indentation is used to declare a block. If
two statements are at the same indentation level, then they are the part of the same block.

Generally, four spaces are given to indent the statements which are a typical amount of
indentation in python.

Indentation is the most used part of the python language since it declares the block of
code. All the statements of one block are intended at the same level indentation. We will
see how the actual indentation takes place in decision making and other stuff in python.

14
The if statement :

The if statement is used to test a particular condition and if the condition is true, it
executes a block of code known as if-block. The condition of if statement can be any
valid logical expression which can be either evaluated to true or false.

The if-else statement

The if-else statement provides an else block combined with the if statement which is
executed in the false case of the condition.

The elif statement

The elif statement enables us to check multiple conditions and execute the specific block
of statements depending upon the true condition among them. We can have any number
of elif statements in our program depending upon our need. However, using elif is
optional.

The elif statement works like an if-else-if ladder statement in C. It must be succeeded by
an if statement.

15
Chapter – 2

Generative AI

2.1 About AI

Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that
are programmed to think, learn, and adapt. AI systems are designed to perform tasks that
typically require human intelligence, such as visual perception, speech recognition,
decision-making, and language translation. The field of AI has seen rapid advancements,
especially in recent years, and has become a cornerstone of modern technology. However,
AI is not a completely new concept. Since the early 1000s, AI has been gradually
integrated into various aspects of our daily lives, often without us even realizing it. For
instance, search engines use AI to provide search suggestions based on user behaviour,
translating text between languages in real-time, and even recommending products or
content based on past interactions. These early implementations of AI laid the foundation
for the more sophisticated and advanced AI systems we see today, such as those used in
autonomous vehicles, virtual assistants, and, most recently, Generative AI.

In summary, AI has been an evolving force in technology for decades, constantly


improving and expanding its applications. Its impact is pervasive, touching almost every
aspect of modern life, and it continues to push the boundaries of what machines can
achieve.

2.1 Generative AI
Generative AI is a subset of artificial intelligence focused on creating new content, ideas,
or solutions by leveraging existing data. Unlike traditional AI systems, which are
16
primarily designed to recognize patterns or make decisions based on predefined rules or
past data, generative AI models are capable of producing novel outputs that resemble the
patterns found in the data they were trained on.
At the core of generative AI are complex models such as Generative Adversarial
Networks (GANs), Variational Autoencoders (VAEs), and Transformer-based
architectures like GPT (Generative Pretrained Transformer). These models are trained on
large datasets and learn to understand the underlying structure of the data. Once trained,
they can generate new content that is often indistinguishable from human-created content.
This includes generating realistic images, composing music, writing text, and even
creating complex designs. or instance, GPT models, like the one used by OpenAI, are
capable of generating
coherent and contextually relevant text based on a given prompt. This has numerous
applications, from writing articles and creating marketing content to answering questions
and assisting with coding tasks. Similarly, GANs have been used to create highly realistic
images of faces, scenes, and objects that do not exist in reality.
Generative AI has profound implications across various industries. In the creative arts, it
can assist in generating new artistic works or providing inspiration. In healthcare, it can
be used to create synthetic data for training models without compromising patient
privacy. In design and engineering, generative AI can explore countless design variations,
helping to innovate faster and more efficiently.
Despite its potential, generative AI also raises ethical and practical concerns. The ability
to create realistic fake content, such as deepfakes, poses significant challenges in areas
like security, privacy, and the spread of misinformation. Therefore, while generative AI
offers exciting possibilities, it also necessitates careful consideration and responsible use.
In conclusion, generative AI represents a significant leap forward in the field of artificial
intelligence, enabling machines to not only learn from data but also to create new,
innovative outputs. Its applications are vast and varied, promising to reshape industries
and creative processes alike.

2.3 Language Modeling


Language modeling is a fundamental task in natural language processing (NLP) that
involves predicting the next word in a sequence, given the preceding context. For
instance, in the sentence "The colour of the sky is…," a language model would likely

17
predict the word "blue" as the next word. Language models are crucial in various
applications, such as text generation, speech recognition, machine translation, and more.

2.3.1 Neural Network Language Models (NNLM)


Neural Network Language Models (NNLMs) leverage neural networks to predict the
likelihood of a sequence of words. Unlike traditional language models that rely on
simpler statistical methods, NNLMs can capture complex patterns and relationships
between words in a text. These models typically involve training a neural network to
understand the context of a word sequence and generate predictions accordingly.
While earlier NNLMs were effective, they had limitations in terms of scalability and
efficiency. This led to the development of more advanced architectures, such as
Transformers, which are now the backbone of modern language models. Transformers
use attention mechanisms to weigh the importance of different words in a sequence,
making them far more powerful and capable of understanding and generating language in
a more nuanced way.

3.3.1 Large Language Models (LLMs)


Large Language Models (LLMs) represent a significant evolution in language modeling.
Since 1018, the size and complexity of these models have grown exponentially. LLMs,
such as GPT-4, are designed with an enormous number of parameters—often in the
trillions—allowing them to process and generate text that is increasingly sophisticated
and human-like. For context, GPT-4 has around 1 trillion parameters, approaching the
complexity of the human brain, which contains approximately 100 trillion synapses.

LLMs have transformed NLP, enabling applications that were previously unimaginable.
They can generate coherent essays, engage in complex conversations, translate languages
with high accuracy, and even assist in creative writing. However, their vast size and
capability also come with challenges, including the need for massive computational

18
resources and the potential for generating biased or misleading content.
In summary, the transition from traditional neural network language models to large
language models marks a significant milestone in AI and NLP, paving the way for more
advanced and capable systems that can understand and generate human language with
unprecedented accuracy and depth.

Chapter – 3

GUI

Graphical User Interface (GUI) programming in Python allows developers to create user-
friendly interfaces for applications. Python provides several libraries and frameworks to
build GUIs, each with its own strengths and use cases.

3.1 About GUI and Tkinter

A Graphical User Interface (GUI) is a visual interface that allows users to interact with
electronic devices through graphical elements like windows, buttons, icons, and text.
GUIs make it easier for users to interact with software by providing a more intuitive and
visually engaging way to control applications, compared to text-based interfaces. GUIs
are a fundamental aspect of modern software, enhancing user experience by making33
complex tasks more accessible.
Tkinter is a standard Python library used to create GUI applications. It provides a simple
way to design and implement a wide range of GUI elements, such as buttons, labels, text
boxes, menus, and more. Tkinter is often chosen for GUI development in Python due to
its ease of use, cross-platform compatibility, and integration with Python’s extensive
libraries.
Tkinter is built on top of the Tcl/Tk GUI toolkit, a well-established and widely used
toolkit for creating GUIs. It abstracts many of the complexities involved in GUI
programming, allowing developers to focus more on the design and functionality of their
applications rather than on the intricacies of GUI implementation. With Tkinter, even
19
beginners can quickly create functional and visually appealing GUI applications in
Python.
In summary, Tkinter serves as a powerful and accessible tool for developing GUI
applications in Python, providing the essential features needed to build interactive and
user-friendly software.

3.2 Setting Up Tkinter


To begin developing GUI applications using Tkinter in Python, you first need to set it up
by installing the library and importing it into your Python environment. Here’s how you
can do that:

3.2.1 Installing Tkinter (MacOS):


To check if Tkinter is installed, you can try running a simple Python script that imports
Tkinter. If you get an error, then you’ll need to install it.
If Tkinter isn't installed, follow these steps:
1. Open Terminal box
2. Install Tkinter: Use the following command to install Tkinter for Python:
pip install tk
This command will install the necessary files for Tkinter.
3.2.2 Importing Tkinter in Python
After ensuring Tkinter is installed, you can start using it by importing it into your Python
script with the following line:
import tkinter as tk
This line of code imports the Tkinter library, allowing you to use its functions and classes
for creating GUI applications.
By following these steps, you’ll have Tkinter ready to use in your Python projects.

3.3 Integrating Tkinter with Other Libraries


Tkinter is a versatile library for creating GUI applications in Python, and its power can be
significantly enhanced by integrating it with other Python libraries. This integration

20
allows you to add more functionality to your applications, such as data visualization,
database management, or even web-based features.

3.3.1 Integrating Tkinter with Matplotlib


Matplotlib is a popular Python library for creating static, animated, and interactive
visualizations. Integrating Matplotlib with Tkinter allows you to display charts and
graphs directly in your GUI.
To integrate Matplotlib with Tkinter, you first need to install Matplotlib using pip:
pip install matplotlib
3.3.1 Integrating Tkinter with Web APIs
You can also integrate Tkinter with web-based libraries like requests to fetch and display
data from web APIs.
To fetch data from a web API and display it in a Tkinter GUI, you need to install the
requests library:
pip install requests

3.4 Creating a Simple GUI


In this section, we developed a basic graphical user interface (GUI) for a Flipkart login
page using Tkinter. This GUI includes fields for email and password input, along with a
login button that triggers a function to validate the credentials. The interface was designed
with a simple, user-friendly layout that reflects the Flipkart brand through its
colour scheme and logo.
The GUI leverages the Tkinter library for the main interface elements and the PIL
(Python Imaging Library) for handling image display. The functionality includes basic
user input handling and condition-based messaging to indicate successful or failed login
attempts.

3.4.1 Code:

21
Figure 3.1 Code for login page using tkinter

3.4.2 Output

Figure 3.2 Output of login page


22
Chapter 4
HUGGING FACE
Hugging Face is a leading platform and library in the field of Natural Language
Processing
(NLP) that provides tools to work with state-of-the-art models for a wide range of tasks,
such as text classification, translation, summarization, question answering, and more.
The
most popular library from Hugging Face is transformers, which allows easy access to
pre-
trained models and pipelines for various NLP tasks.
4.1 Overview of Hugging Face in Python
1. Installation
To start using Hugging Face's tools in Python, you need to install the transformers
library:
transformers library:
bash
Copy code
pip install transformers
If you're working with datasets, you might also want to install the datasets library:
bash
Copy code
pip install datasets
4.2. Using Pre-trained Models
Hugging Face provides a simple way to use pre-trained models through its pipeline
function. Here's an example of how to perform sentiment analysis:
python
Copy code
from transformers import pipeline
# Load a pre-trained sentiment analysis model
classifier = pipeline("sentiment-analysis")
# Perform sentiment analysis
result = classifier("I love programming with Python!")
23
print(result)
This code will output something like:
python
Copy code20
[{'label': 'POSITIVE', 'score': 0.9998}]
4.3. Working with Specific Models
You can also load and use specific models directly by their names or from the Hugging
Face Model Hub:
python
Copy code
from transformers import
AutoModelForSequenceClassification, AutoTokenizer
# Load a pre-trained model and tokenizer
model_name = "bert-base-uncased"
model =
AutoModelForSequenceClassification.from_pretrained(model_na
me)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Tokenize input text
inputs = tokenizer("Hello, Hugging Face!",
return_tensors="pt")
# Perform inference
outputs = model(**inputs)
4.4. Popular Tasks
Here are some common NLP tasks you can perform using Hugging Face:
• Text Classification:
python
Copy code
classifier = pipeline("text-classification")
result = classifier("The movie was fantastic!")
• Text Generation:
python
Copy code
24
generator = pipeline("text-generation", model="gpt2")
result = generator("Once upon a time,")
• Named Entity Recognition (NER):
python
Copy code
ner = pipeline("ner", grouped_entities=True)
result = ner("Hugging Face Inc. is based in New York
City.")
• Question Answering:21
python
Copy code
qa = pipeline("question-answering")
result = qa(question="Where is Hugging Face based?",
context="Hugging Face Inc. is
based in New York City.")
• Translation:
python
Copy code
translator = pipeline("translation_en_to_fr")
result = translator("Hello, how are you?")
4.5. Fine-Tuning and Customization
Hugging Face also allows you to fine-tune models on your own data. This is
particularly
useful if you need a model to perform well on a specific domain or dataset.
python
Copy code
from transformers import Trainer, TrainingArguments
# Define training arguments
training_args = TrainingArguments(
output_dir='./results',
num_train_epochs=3,
per_device_train_batch_size=8,
per_device_eval_batch_size=8,
25
warmup_steps=500,
weight_decay=0.01,
logging_dir='./logs',
)
# Create a Trainer object
trainer = Trainer(
model=model,
args=training_args,
train_dataset=train_dataset,
eval_dataset=eval_dataset
)
# Start fine-tuning22
trainer.train()
4.5 Using Datasets with Hugging Face
The datasets library provides access to a wide range of datasets that can be used with
models. You can load a dataset as follows:
python
Copy code
from datasets import load_dataset
# Load the IMDB dataset
dataset = load_dataset("imdb")
print(dataset['train'][0])
4.6. Model Hub
The Hugging Face Model Hub is a central place where you can find and share pre-
trained
models. You can load any model directly from the hub using its name.
python
Copy code
from transformers import pipeline
# Load a translation model from the Model Hub
translator = pipeline("translation_en_to_de",
model="Helsinki-NLP/opus-mt-en-de")
# Translate text
26
result = translator("Hello, how are you?")
print(result)

Chapter 5
PROJECT UNDERTAKEN

5.1 Text to image Generator


below is the detailed explanation of the simple streamlit app project
5.1.1. Imports:-
• requests: For making HTTP requests to the API
• io: For handling byte streams.
• PIL (Python Imaging Library): For opening and manipulating images.
• matplotlib.pyplot: For displaying images.
5.1.2. API Setup:-
• API_URL: The endpoint for the Stable Diffusion model on Hugging Face.
• headers: Contains the authorization token for accessing the API.
5.1.3. Function to Query the Hugging Face API:-
• query(payload): Sends a POST request with the specified payload (input text) to the
API.
• Checks if the response status is 200 (success). If successful, it returns the content
(image
bytes). Otherwise, it prints an error message and returns None.
5.1.4. Query the API:
- Sends a query to the API with the input text "olympics" and stores the returned image
bytes.
5.1.5. Check and Display the Image:
• Checks if image_bytes is not None.
• Tries to open the image bytes using PIL.Image.open and displays it using
matplotlib.pyplot.
• If the image cannot be identified, it prints an error message.

27
5.1.6 Code

Figure 5.1 Code for Text to Image Generator

28
5.1.7 Output

Figure 5.2 Output of text to image generator

5.2 CHATBOT
5.2.1 Chatbot Application :-
Theory:- below is the detailed explanation of the chatbot application project
5.2.1.1 Imports and Setup
• tkinter and tkinter.scrolledtext: Used to create the GUI application
• requests: Used to make HTTP requests to the Hugging Face API.
• API_URL: The URL endpoint for the Hugging Face BERT model
• headers
Contains the authorization token needed to access the API. Replace
"hf_wiHvXMOuzIypWbtsPnheQEmoSMvdqrzuxqO" with my actual token.
5.2.1.2. Functions:
• This function takes a payload (a dictionary with input data) and sends a POST request to
the Hugging Face API.26
• It returns the JSON response from the API.
• This function retrieves the user's question and context from the text fields
• It sends these inputs to the query function to get a response from the API.
29
• The response is displayed in the response text area of the GUI.
• If there is a KeyError (e.g., if the API response doesn't contain the expected answer
key),
it displays an error message.
5.2.1.3. GUI Setup:
• root = tk.Tk(): Initializes the main window of the application.
• root.title("GenAI QUES & ANS"): Sets the title of the window
• A label (context_label) and a scrolled text widget (context_entry) for the user to input
the context.
• pack() methods are used to add these widgets to the window
• A label (question_label) and a scrolled text widget (question_entry) for the user to input
the question.
• These widgets are also added to the window using pack().
• A button (get_response_button) that triggers the get_response function when clicked.
• Added to the window using pack().
• A label (response_label) and a scrolled text widget (response_text) for displaying the
response from the API.
• The response text area is initially disabled to prevent user edits.
5.2.1.4. Main Loop:-
• root.mainloop():
Starts the Tkinter event loop, which keeps the window
5.2.1.5 Code

30
Figure 5.3 Code of Chatbot

31
5.2.1.6 Output

Figure 5.4 Output of Chatbot

32
CONCLUSION
This report captures the key learning outcomes from the Summer Industrial Training
Program, which covered essential areas like Python, Streamlit, Tkinter, Generative AI,
and API Integration. Each chapter of the report offers a focused exploration of these
technologies, enhancing my understanding of modern software development practices.
The training began with an introduction to Generative AI, laying the groundwork for
understanding advanced AI models and their applications. The transition from Neural
Network Language Models (NNLM) to Large Language Models (LLM) was discussed,
highlighting the rapid growth in model complexity.
Practical skills were developed through chapters on Tkinter and Streamlit, where I
created interactive applications like a Flipkart login page and a text-to-image generator.
These chapters provided hands-on experience in setting up tools, integrating libraries, and
deploying applications.
The report also delves into API Integration, particularly with Hugging Face models,
demonstrating how pre-trained models can enhance application functionality. This was
exemplified by the development of a Chat Bot, showcasing the practical use of APIs.
Finally, the report covers real-world projects that applied the theoretical knowledge
gained, reinforcing the importance of integrating various technologies to create functional
applications.
In summary, this training significantly advanced my technical skills, providing a solid
foundation for future endeavours in software development. It equipped me with the
knowledge to navigate the complexities of modern tech, preparing me for continued
growth in the field.

33
REFERENCE

1. Brigham, E. F., & Ehrhardt, M. C. (2016). Financial Management: Theory &


Practice (15th ed.). Cengage Learning.
2. Higgins, R. C. (2012). Analysis for Financial Management (10th ed.). McGraw-Hill
Education.
3. Koller, G., Goedhart, M., & Wessels, D. (2015). Valuation: Measuring and
Managing the Value of Companies (6th ed.). Wiley.
4. Palepu, K. G., Healy, P. M., & Bernard, V. L. (2012). Business Analysis and
Valuation: Using Financial Statements (5th ed.). Cengage Learning.
5. Wild, J. J., Subramanyam, K. R., & Halsey, R. F. (2014). Financial Statement
Analysis (11th ed.). McGraw-Hill Education.
6. Ross, S. A., Westerfield, R. W., & Jordan, B. D. (2018). Essentials of Corporate
Finance (10th ed.). McGraw-Hill Education.
7. Fridson, M. S., & Alvarez, F. (2011). Financial Statement Analysis: A Practitioner’s
Guide (3rd ed.). Wiley.
8. Gibson, C. H. (2013). Financial Statement Analysis (12th ed.). South-Western College
Pub.
9. Damodaran, A. (2012). Investment Valuation: Tools and Techniques for Determining
the Value of Any Asset (3rd ed.). Wiley.
10. Tennent, M. (2018). Understanding Financial Statements: A Guide for the Non-
financial Manager (2nd ed.). Financial Times/Prentice Hall.

34

You might also like