import gradio as gr from langchain.chat_models import ChatOpenAI from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate from langchain.chains import LLMChain import os def process_request(automobile, malfunctions, faulty_parts): template = """ Respond in systematically cleaned-up Markdown format and only in Russian: You are a virtual technical assistant with years of experience in repairing, conducting specialized diagnostics, and accurately identifying the causes of malfunctions in {automobile} vehicles. Car owners come to you with complaints about technical problems with their cars that may affect the safety of operation. They are not specialists and may inaccurately describe the nature of the malfunctions. Now we will discuss the malfunctions of the {automobile} that we received from the owner. I need your expert opinion and recommendations on the following points: 1. Analysis of malfunctions {malfunctions}: - Consider each malfunction separately, classifying them by possible causes. - Rank the causes by their influence on the manifestation of the malfunction. 2. Grouping problems. Combine malfunctions that have common root causes. 3. Assessment of information sufficiency: - Assess whether the information provided is sufficient for diagnosis. - Ask clarifying questions with a brief explanation of their necessity. - Indicate any additional data that will help you provide accurate and useful recommendations for troubleshooting. When forming a response, adhere to the format - the number or numbers of the malfunction and then your request to clarify the data with a brief explanation of the reason for such clarifications. 4. Alternative solutions. Suggest less costly methods of solution, if possible. """ prompt = ChatPromptTemplate( messages=[ HumanMessagePromptTemplate.from_template(template) ], input_variables=["automobile", "malfunctions", "faulty_parts"] ) llm = ChatOpenAI(temperature=0, model_name="gpt-4o") chain = LLMChain(llm=llm, prompt=prompt) result = chain.run(automobile=automobile, malfunctions=malfunctions, faulty_parts=faulty_parts) return result iface = gr.Interface( fn=process_request, inputs=[ gr.Textbox(label="Автомобиль (Марка, Модель, Характеристики)", placeholder="например, Toyota Camry 2018, двигатель 2.5L"), gr.Textbox(label="Сообщенные неисправности", placeholder="например, Пропуски зажигания, неровный холостой ход, сниженная топливная эффективность"), gr.Textbox(label="Возможные неисправные детали", placeholder="например, Свечи зажигания, форсунки, датчик кислорода") ], outputs=[gr.Markdown(label="Ответ AI помощника")], title="AI помощник по обслуживанию автомобилей", description="Введите данные о транспортном средстве и сообщенные проблемы, чтобы получить экспертные рекомендации по устранению неисправностей от AI помощника.", examples=[ ["Honda Civic 2015, двигатель 1.8L", "Скрип при торможении, вибрация в рулевом колесе", "Тормозные колодки, диски, подшипники колес"], ["Ford F-150 2019, 3.5L EcoBoost", "Задержка переключения передач, проскальзывание трансмиссии", "Трансмиссионная жидкость, соленоиды, фрикционные диски"], ["Nissan Altima 2017, двигатель 2.5L", "Кондиционер не охлаждает, затхлый запах из вентиляционных отверстий", "Фильтр салона, компрессор кондиционера, утечка хладагента"] ] ) iface.launch()