import gradio as gr # Define the conversation flow with predefined questions and answers conversation_flow = { "hello": "Hi there! How can I help you?", "about ocular disease": "Ocular cattle disease, also known as infectious bovine keratoconjunctivitis, is a contagious eye infection affecting cattle. It is caused by bacteria like Moraxella bovis and spreads through direct contact or contaminated environments. The disease leads to painful inflammation, discharge, and in severe cases, can cause blindness, impacting the health and productivity of the affected cattle.", "ocular disease": "Ocular cattle disease, also known as infectious bovine keratoconjunctivitis, is a contagious eye infection affecting cattle. It is caused by bacteria like Moraxella bovis and spreads through direct contact or contaminated environments. The disease leads to painful inflammation, discharge, and in severe cases, can cause blindness, impacting the health and productivity of the affected cattle.", "ocular disease treatment": "Treatment for ocular cattle disease typically involves administering antibiotics such as oxytetracycline or florfenicol to combat the bacterial infection. In addition to antibiotics, supportive care like eye ointments and pain relief medications may be provided to alleviate discomfort and promote healing. Proper hygiene, quarantine measures, and vaccination can also help prevent the spread of the disease within the cattle herd.", "medicine for ocular disease":"Medicines for ocular diseases vary depending on the specific condition. Common treatments include antibiotic eye drops or ointments to combat infections caused by bacteria, antiviral medications for viral infections like herpes simplex keratitis, and anti-inflammatory drugs to reduce swelling and discomfort. In some cases, lubricating eye drops or artificial tears are used to alleviate dryness and irritation, providing relief for various ocular disorders.", "ocular disease prevention":"Preventing ocular diseases in cattle requires implementing proper herd management practices, including maintaining clean and dry living conditions to minimize bacterial contamination. Regular vaccination against common pathogens like Moraxella bovis can significantly reduce the risk of infectious bovine keratoconjunctivitis. Additionally, providing adequate nutrition, minimizing stress, and ensuring proper eye protection in areas prone to dust or irritants are essential measures to safeguard cattle from ocular diseases.", "default": "I'm not sure how to respond to that. Can you ask me something else?" } # Define the chatbot class class Chatbot: def __init__(self): self.chat_history = [] def respond(self, user_input): # Check if the input text matches predefined questions if user_input.lower() in conversation_flow: response = conversation_flow[user_input.lower()] else: # If the input doesn't match, use the default response response = conversation_flow["default"] # Add the user input and chatbot response to the chat history self.chat_history.append({"user": user_input, "bot": response}) # Format the chat history as a conversation chat_history_formatted = "" for chat in self.chat_history: chat_history_formatted += f'User: {chat["user"]}
Bot: {chat["bot"]}

' return chat_history_formatted # Create a Chatbot instance chatbot = Chatbot() # Create a Gradio interface for the chatbot chatbot_interface = gr.Interface(fn=chatbot.respond, inputs="text", outputs="html", title="Chat with Chatbot") chatbot_interface.launch()