Taf-gpt / app.py
Tafar's picture
Update app.py
026cf04
raw
history blame contribute delete
No virus
4.32 kB
from chatbot_ui import run_chat_ui
import gradio as gr
topics = ["finance", "music", "sports", "technology", "health care"]
def generate_ai_blog():
return (
"**How Artificial Intelligence Impacts in Everyday Lives and Industries**\n\n"
"## Introduction:\n\n"
"Artificial Intelligence (AI) has emerged as a transformative force, reshaping various aspects of our daily lives and industries. "
"From personalized recommendations on streaming platforms to advanced automation in manufacturing, AI has become an integral part of our interconnected world.\n\n"
"## Subheading 1: Enhancing Daily Convenience:\n\n"
"In the realm of everyday life, AI manifests in applications that enhance convenience. Virtual assistants, like Siri and Alexa, leverage AI to understand and respond to natural language, providing hands-free assistance for tasks ranging from setting reminders to answering queries. Smart home devices utilize AI algorithms to learn user preferences, adjusting climate control, and lighting to optimize comfort.\n\n"
"## Subheading 2: Revolutionizing Industries:\n\n"
"In industries, the impact of AI is profound, ushering in a new era of efficiency and innovation. Automation powered by AI streamlines manufacturing processes, reducing errors and increasing productivity. In healthcare, AI algorithms analyze vast datasets to aid in diagnostics and treatment planning, fostering more accurate and personalized patient care.\n\n"
"## Subheading 3: Transforming Decision-Making:\n\n"
"AI's analytical capabilities are revolutionizing decision-making across sectors. Businesses leverage AI-driven analytics to gain insights from large datasets, informing strategic decisions and predicting market trends. In finance, algorithms analyze market data in real-time, optimizing investment strategies and risk management. The predictive power of AI is transforming decision landscapes, empowering industries to adapt and thrive in a dynamic environment.\n\n"
"## Conclusion:\n\n"
"As we navigate the evolving landscape of technology, the impact of AI on everyday lives and industries is undeniable. From simplifying daily tasks to redefining industrial processes, artificial intelligence continues to shape the way we live and work. Embracing the potential of AI opens doors to unprecedented possibilities, promising a future where innovation and efficiency coexist to enrich our lives and drive progress."
)
def process_feedback(feedback_value, history):
if feedback_value:
feedback_index = {"πŸ‘": 1, "πŸ‘Ž": -1}[feedback_value]
last_user_message, last_bot_response = history[-1]
# Use the feedback to update the bot's response in a simple way
history[-1][1] = f"{last_bot_response} (Feedback: {feedback_index})"
print(f"Feedback received: {feedback_value} for: {last_user_message} - {last_bot_response}")
def user(user_message, chatbot, feedback):
# Extract topic from the user's message
topic = next((t for t in topics if t in user_message.lower()), None)
# Check if the user is asking for a blog
if "blog" in user_message.lower():
blog_text = generate_ai_blog()
# Append the blog output to the chat history
return blog_text, [user_message, blog_text]
# Respond based on the detected topic
elif topic:
return f"Sure, let's talk about {topic}!", [user_message, None]
else:
return "I'm not sure which topic you're referring to. Please specify one of: " + ", ".join(topics), [user_message, None]
def bot(history):
# Check the last user message for the detected topic
last_user_message = history[-1][0].lower() if history else ""
topic = next((t for t in topics if t in last_user_message), None)
# Respond based on the detected topic or provide a generic response
if topic:
response = history[-1][1]
else:
response = "That's interesting! What else would you like to talk about?"
history[-1][1] = response
return response
def clear(chatbot):
chatbot = gr.Chatbot()
demo = gr.Interface(
fn=user,
inputs=["text", "chat", "radio"],
outputs=["text", "chat"]
)
if __name__ == "__main__":
run_chat_ui()
demo.launch(share=True)