Skip to content

Commit

Permalink
Merge pull request #367 from spandana2004/main
Browse files Browse the repository at this point in the history
Chatbot to learn GenAI
  • Loading branch information
UppuluriKalyani authored Oct 16, 2024
2 parents 925f677 + 3402a99 commit 87fbe32
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Generative Models/Chatbot-learn-GenAI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Generative AI Learning Chatbot

This project is an interactive chatbot designed to help users learn about Generative AI. The chatbot is built using **Streamlit** and **DialoGPT**, and it integrates a knowledge base of Generative AI concepts along with a quiz functionality.

## Features

- **Generative AI Knowledge Base:** The chatbot can answer pre-defined questions about Generative AI concepts such as Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), and their applications.

- **Quiz Functionality:** Users can engage with quiz questions related to Generative AI. Users can type `quiz` to receive a question, and then input the question in the format `Quiz: [question]` to see the answer.

- **DialoGPT Integration:** For any question that is not in the predefined knowledge base, the chatbot uses the **DialoGPT** model from Hugging Face’s transformers library to generate a text-based response.

## How to Run the Project

### Prerequisites

1. Python 3.7+
2. Install required libraries using pip:
```bash
pip install streamlit transformers
```

### Running the Chatbot

1. Clone this repository:
```bash
git clone <repository-url>
cd <repository-directory>
```

2. Run the Streamlit app:
```bash
streamlit run chatbot.py
```

3. The chatbot will open in your web browser, and you can start interacting with it.

### Sample Interaction

- Ask about Generative AI:
```
You: What is Generative AI?
Chatbot: Generative AI refers to a category of artificial intelligence techniques that create new data instances that resemble existing data. Examples include Generative Adversarial Networks (GANs) and Variational Autoencoders (VAEs).
```

- Take a quiz:
```
You: quiz
Chatbot: Here’s a quiz question for you. Type 'Quiz: [question]' to see the answer.
```

```
You: Quiz: What is the purpose of the discriminator in a GAN?
Chatbot: Quiz: What is the purpose of the discriminator in a GAN? (Answer: To distinguish between real and generated data.)
```

## Code Structure

- `chatbot.py`: Contains the main code for the chatbot, including the knowledge base, quiz handling logic, and integration with DialoGPT.

## Future Enhancements

- **Expand Knowledge Base:** Add more detailed information and concepts related to Generative AI.
- **Improve Quiz Functionality:** Implement more advanced quiz interactions, such as scoring or random question selection.
- **Personalization:** Integrate user-specific learning paths or history-based interactions.
66 changes: 66 additions & 0 deletions Generative Models/Chatbot-learn-GenAI/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Install necessary libraries
# !pip install transformers
# !pip install torch
# !pip install streamlit

import streamlit as st
from transformers import pipeline

# Initialize the text generation pipeline with DialoGPT
chatbot = pipeline("text-generation", model="microsoft/DialoGPT-medium")

# Define the knowledge base for Generative AI concepts
knowledge_base = {
"What is Generative AI?": "Generative AI refers to a category of artificial intelligence techniques that create new data instances that resemble existing data. Examples include Generative Adversarial Networks (GANs) and Variational Autoencoders (VAEs).",
"What is a GAN?": "A Generative Adversarial Network (GAN) consists of two neural networks, a generator and a discriminator, that compete against each other to generate new, synthetic instances of data that resemble real data.",
"What is a VAE?": "A Variational Autoencoder (VAE) is a type of generative model that learns to encode input data into a lower-dimensional latent space and then decodes it to generate new data samples.",
"Applications of Generative AI": "Generative AI has various applications, including image generation, text generation, style transfer, data augmentation, and more.",
}

# Define a set of quiz questions and answers
quizzes = {
"What is the purpose of the discriminator in a GAN?": "To distinguish between real and generated data.",
"In a VAE, what does the encoder do?": "It compresses input data into a latent space representation."
}

# Function to generate responses based on the knowledge base
def chatbot_response(user_input):
if user_input.startswith("Quiz:"):
return handle_quiz(user_input[5:].strip())

# Check if the user input matches any predefined questions
response = knowledge_base.get(user_input, None)
if response is not None:
return response
else:
# Generate a response using the text generation pipeline if no match in knowledge base
responses = chatbot(user_input, max_length=100, num_return_sequences=1)
return responses[0]['generated_text']

# Function to handle quiz questions
def handle_quiz(question):
answer = quizzes.get(question, None)
if answer is not None:
return f"Quiz: {question} (Answer: {answer})"
else:
return "No quiz question found for that input. Try another question or ask about Generative AI concepts."

# Streamlit code for the interactive learning chatbot
def main():
st.title("Generative AI Learning Chatbot")

st.write("Hello! I am here to help you learn about Generative AI. Ask me questions or type 'quiz' to take a quiz.")

# Input from user
user_input = st.text_input("You:", placeholder="Ask me about Generative AI or type 'quiz' for a quiz question")

if user_input:
if user_input.lower() == 'quiz':
st.write("Here’s a quiz question for you. Type 'Quiz: [question]' to see the answer.")
else:
# Get response from chatbot
response = chatbot_response(user_input)
st.write(f"Chatbot: {response}")

if __name__ == "__main__":
main()

0 comments on commit 87fbe32

Please sign in to comment.