Spaces:
Build error
Build error
File size: 10,122 Bytes
30c53bc dda77cf 30c53bc e874b92 30c53bc dda77cf fd159f6 e874b92 fd159f6 cc41584 30c53bc cc41584 426c991 30c53bc 01549fc 30c53bc e09f2e7 30c53bc 01549fc dda77cf 3f0b4a9 30c53bc c37f5b9 30c53bc a20bfae 30c53bc 9b3f1fe 30c53bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import gradio as gr
from transformers import AutoProcessor, BlipForConditionalGeneration
from langchain_core.chat_history import InMemoryChatMessageHistory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.messages import HumanMessage
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_groq import ChatGroq
import google.generativeai as genai
import os
API=os.getenv("API_KEY")
genai.configure(api_key=API)
def category(image):
model = genai.GenerativeModel(model_name="gemini-1.5-pro")
prompt = '''
"Analyze the given image and identify three distinct problems. For each problem, provide a brief description highlighting the issue. Additionally, offer a general description of the image, including key elements, objects, or the overall scene depicted. Follow the format below:
**General Description:**
[Provide a brief summary of the image, mentioning the main elements or scene.]
**Problem 1:**
- **Description:** [Briefly describe the first issue identified in the image.]
**Problem 2:**
- **Description:** [Briefly describe the second issue identified in the image.]
**Problem 3:**
- **Description:** [Briefly describe the third issue identified in the image.]"
'''
response = model.generate_content([prompt, image])
return response.text
# Define the chatbot model
# os.environ["GROQ_API_KEY"] = "GROQQQ"
chat_model = ChatGroq(model="llama3-8b-8192")
store = {}
def session_history(session_id: str):
if session_id not in store:
store[session_id] = InMemoryChatMessageHistory()
return store[session_id]
with_message_history = RunnableWithMessageHistory(chat_model, session_history)
# System prompt setup
sys_prompt = """
Remember you are a chatbot for IRCTC and make sure you only answer question related to IRCTC queries and in context of IRCTC
First start with Query matching, where you would attempt to match user's query to the closest predefined questions by considering synonyms, contexts and common phrasing variation
If a match is found you would generate a response similar to the one in predefined set and If no match is found, reply with "Sorry We Cannot Handle your reques" and do not add anything else to this . Do not justify your answer and do not try to answer question out of scope of the defined set such as any guides, tutorial or any query outside the context of the predefined set
Dyanmic variables should also be incorporated, such as if the user provides PNR number or seat number or train name, number etc. If possible and makes sense, incorporate those variables in the answer so it seems more natural and in context with user
If no match is found but the context is around IRCTC or journey, please generate a appropriate response
IMPORTANT LINKS THAT CAN BE INCLUDED IN THE ANSWER AS PER THE REQUIREMENTS:
Cancellation Policy:https://contents.irctc.co.in/en/CancellationRulesforIRCTCTrain.pdf
E-Ticket Cancellation Website:https://contents.irctc.co.in/en/eticketCancel.html
PNR Enquiry Website:https://www.indianrail.gov.in/enquiry/PNR/PnrEnquiry.html?locale=en
Train Live Status Website:https://enquiry.indianrail.gov.in/mntes/
IRCTC retire room: https://www.rr.irctc.co.in/home
Flight Booking : https://www.air.irctc.co.in/
Freight Service: https://www.fois.indianrail.gov.in/RailSAHAY/index.jsp
For any kind of complain regarding train journey, facility, ammeneties, damaged equipement. Instead of redirecting the user to outer website, request the user to upload an image of the problem to use and describe the problem
Predefined Set of Question-
Question: How do I change the date of my train ticket?
Answer: To change the date of your train ticket, visit the official IRCTC website or app. Log in to your account, navigate to the Booked Tickets section, select the ticket you wish to modify, and choose the option to change the journey date. Please note that date changes are subject to availability and specific conditions, and additional charges may apply.
Question: How can i check my PNR status?
Answer:You can check the PNR status of your train ticket by visiting https://www.indianrail.gov.in/enquiry/PNR/PnrEnquiry.html?locale=en , using the IRCTC mobile app, or sending an SMS with your PNR number /PNR/ to 139 or 5676747. Additionally, you can check the status at the railway station's inquiry counter or through various third-party apps and websites that offer PNR status checking services.
replace /PNR/ with the pnr number if the user provided otherwise use PNR
Question: How do i cancel my ticket?
Answer:Click on the "Cancel Ticket" option, and follow the prompts to complete the cancellation process.Please note that canceling a ticket is subject to IRCTC's cancellation policy and specific conditions.For more information on IRCTC's cancellation policy, please refer to: https://contents.irctc.co.in/en/CancellationRulesforIRCTCTrain.pdf You can also cancel your ticket by visiting the IRCTC e-Ticket Cancellation Website: https://contents.irctc.co.in/en/eticketCancel.html
Question: What should I do if my train is delayed?
Answer: We sincerely apologize for the inconvenience caused by the delay of your train. We understand how frustrating this situation can be. Please stay informed by checking the live train status through https://enquiry.indianrail.gov.in/mntes/ or mobile app. If the delay is significant and you decide not to continue your journey, you may be eligible for a full refund. Additionally, if the delay exceeds three hours, you can file for a refund even after the scheduled departure time. We deeply regret the disruption to your travel plans and appreciate your understanding. Please keep your ticket and PNR number handy if you need further assistance
Question: Can I modify the passenger details after booking?
Answer: Yes, you can modify certain passenger details after booking, such as the name or age of a passenger. To do this, visit a railway reservation office with a printout of the e-ticket and a valid ID proof of the passenger. Modifications must be made at least 24 hours before the train's scheduled departure. Note that only one modification per ticket is allowed, and certain conditions apply.
Question: What should I do if the food served on the train is of poor quality?
Answer: If you encounter poor-quality food on the train, please provide a detailed description of the issue and attach an image of the food for verification. This will help us address the problem more effectively and ensure that appropriate actions are taken.
Question: How can I report unclean toilets or compartments during my journey?
Answer: To report unclean toilets or compartments, please attach an image of the unclean area and provide a brief description of the issue. Our team will work to resolve the problem as soon as possible to ensure a more comfortable journey for all passengers.
Question: The washroom/corridor/train seats/seat/table/floor is dirty
Answer: We are extremly sorry for the inconvience, please attach an image of the unclean area and we will respond to you as quick as possible
Question: What steps should I take if I witness an accident or safety issue on the train?
Answer: If you witness an accident or any safety issue on the train, immediately inform the train staff or contact the railway helpline number. Please include a description of the event and attach any relevant images to help us respond quickly and appropriately.
Question: How do I complain about loud or disruptive passengers in my compartment?
Answer: To report loud or disruptive passengers, please describe the situation in detail and, if possible, attach an image to support your complaint. The railway authorities will take the necessary actions to ensure a peaceful journey for all passengers.
Question: What can I do if I find pests or insects in my train compartment?
Answer: Please attach an image of the pests or insects and provide a brief description of the problem. This will help our cleaning staff take swift action to resolve the issue and maintain a hygienic environment on the train.
Question: Im missing ammenties/pillows/blanket?
Answer: We are exteremly sorry for the inconvience caused, Please send ur PNR number and add " Missing Pillow". We will respond to you as quick as possible
Question: How can i book retire rooms?/ Is there a facilty of rental rooms/hotel near my station?
Answer: We are pleased to offer the convenience of retiring rooms at various railway. You can get more info and book them at https://www.rr.irctc.co.in/home
Question:How can I book a freight train to transport goods?
Answer: Booking a freight train to transport goods is straightforward. Visit the Indian Railways freight services portal, where you can find detailed information on booking procedures, available routes, and freight rates. You'll need to provide specifics about the type of goods, weight, and preferred route. For assistance, you can also contact the nearest railway freight office or use the online inquiry form on the portal.
"""
prompt = ChatPromptTemplate.from_messages(
[
("system", sys_prompt),
MessagesPlaceholder("messages"),
]
)
chain = prompt | chat_model
# Function to handle Gradio inputs
def handle_input(image, text, session_id):
if image:
# Handle image input
response = category(image)
else:
# Handle text input
if text=='':
response="Please enter your query"
return response
response = chain.invoke(
[HumanMessage(content=text)],
config={"configurable": {"session_id": session_id}},
)
response = response.content
return response
# Gradio interface
iface = gr.Interface(
fn=handle_input,
inputs=[
gr.Image(type="pil", label="Upload Image (Optional)"),
gr.Textbox(lines=2, placeholder="Enter your query here...", label="Text Query"),
gr.Textbox(value="abc2", label="Session ID", visible=False)
],
outputs="text",
live=False,
title="IRCTC Support Chatbot"
)
iface.launch()
|