Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
class TafGPT:
|
| 4 |
+
def generate_response(self, user_input):
|
| 5 |
+
technology_topics = {
|
| 6 |
+
"machine learning": "Machine learning is a fascinating field that involves training computers to learn from data and make predictions.",
|
| 7 |
+
"python programming language": "Python is a versatile programming language known for its simplicity and readability. It's widely used in various domains, including web development and data science.",
|
| 8 |
+
"web development": "Web development includes designing and building websites. Front-end development focuses on user interfaces, while back-end development handles server-side logic.",
|
| 9 |
+
"artificial intelligence": "Artificial Intelligence (AI) refers to the simulation of human intelligence in machines, enabling them to perform tasks that typically require human intelligence.",
|
| 10 |
+
"data science": "Data science involves extracting insights and knowledge from structured and unstructured data. It combines expertise in statistics, mathematics, and programming.",
|
| 11 |
+
"cybersecurity": "Cybersecurity aims to protect computer systems, networks, and data from cyber threats and attacks. It includes measures to ensure the confidentiality, integrity, and availability of information.",
|
| 12 |
+
"cloud computing": "Cloud computing provides on-demand access to computing resources, such as storage, processing power, and databases, over the internet.",
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if user_input.lower() in technology_topics:
|
| 16 |
+
response = f"Taf-gpt: {technology_topics[user_input.lower()]}"
|
| 17 |
+
else:
|
| 18 |
+
response = "Taf-gpt: I'm sorry, I'm specialized in technology topics. Feel free to ask me about machine learning, Python programming language, web development, artificial intelligence, data science, cybersecurity, or cloud computing!"
|
| 19 |
+
|
| 20 |
+
return f"User: {user_input}\n{Taf-gpt: {response}"
|
| 21 |
+
|
| 22 |
+
# Create an instance of TafGPT
|
| 23 |
+
taf_gpt = TafGPT()
|
| 24 |
+
|
| 25 |
+
# Define Gradio interface
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=taf_gpt.generate_response,
|
| 28 |
+
inputs=gr.Textbox(),
|
| 29 |
+
outputs=gr.Textbox(),
|
| 30 |
+
live=True,
|
| 31 |
+
title="Taf-gpt Technology Chatbot",
|
| 32 |
+
description="Explore technology topics with Taf-gpt! Choose a predefined topic or ask your own questions.",
|
| 33 |
+
examples=[
|
| 34 |
+
["Tell me about machine learning"],
|
| 35 |
+
["What is Python programming language?"],
|
| 36 |
+
["Web development best practices"],
|
| 37 |
+
["What is artificial intelligence?"]
|
| 38 |
+
],
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Launch the Gradio interface
|
| 42 |
+
iface.launch()
|