Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,10 +62,10 @@ def chat_query(question, history):
|
|
| 62 |
|
| 63 |
|
| 64 |
query = f"""As an experienced Electrical Engineer, please provide an elaborate, precise, and answer politely pointwise to the question: {question}.
|
| 65 |
-
Also, Please consider the provided chat history: {
|
| 66 |
-
Ensure that your response is detailed, accurate, and addresses each aspect of the question thoroughly.
|
| 67 |
-
If the context of the question doesn't align with
|
| 68 |
-
If don't get the answer, feel free to reply from
|
| 69 |
|
| 70 |
#llm = ChatOpenAI(model=llm_name, temperature=0.1, api_key = OPENAI_API_KEY)
|
| 71 |
llm = GoogleGenerativeAI(model="gemini-1.0-pro", google_api_key=GEMINI_API_KEY)
|
|
@@ -78,17 +78,20 @@ def chat_query(question, history):
|
|
| 78 |
# Replace input() with question variable for Gradio
|
| 79 |
result = qa({"question": query, "chat_history" : chat_history})
|
| 80 |
|
| 81 |
-
|
| 82 |
source_docs = result["source_documents"]
|
| 83 |
-
|
| 84 |
-
file_name = os.path.basename(source_docs[0].metadata['source'])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
return result["answer"] + "\n\
|
| 87 |
|
| 88 |
|
| 89 |
iface = gr.ChatInterface(
|
| 90 |
fn=chat_query,
|
| 91 |
-
#title=" --
|
| 92 |
description="""-- Welcome to the Language Model trained on `Model Technical Specifications` of SS-Engg. Dept.\n\n
|
| 93 |
-- The Model tries to answer the Query based on TS, GTR & Specific Requirements. \n\n
|
| 94 |
-- For precise reply, please input `Specific Keywords` in your Query. \n\n """,
|
|
@@ -104,15 +107,17 @@ iface = gr.ChatInterface(
|
|
| 104 |
|
| 105 |
)
|
| 106 |
|
| 107 |
-
Title= "# --
|
| 108 |
|
| 109 |
|
| 110 |
with gr.Blocks(css="style.css", fill_height=True) as demo:
|
| 111 |
with gr.Row():
|
| 112 |
with gr.Column(scale=1):
|
| 113 |
-
gr.Image("
|
| 114 |
with gr.Column(scale=10):
|
| 115 |
gr.Markdown(Title)
|
|
|
|
|
|
|
| 116 |
|
| 117 |
iface.render()
|
| 118 |
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
query = f"""As an experienced Electrical Engineer, please provide an elaborate, precise, and answer politely pointwise to the question: {question}.
|
| 65 |
+
Also, Please consider the provided chat history: {history}.
|
| 66 |
+
Ensure that your current response is detailed, accurate, and addresses each aspect of the question thoroughly.
|
| 67 |
+
If the context of the question doesn't align with your last reply, please provide your response in a fresh manner.
|
| 68 |
+
If don't get the answer, feel free to reply from your own knowledge."""
|
| 69 |
|
| 70 |
#llm = ChatOpenAI(model=llm_name, temperature=0.1, api_key = OPENAI_API_KEY)
|
| 71 |
llm = GoogleGenerativeAI(model="gemini-1.0-pro", google_api_key=GEMINI_API_KEY)
|
|
|
|
| 78 |
# Replace input() with question variable for Gradio
|
| 79 |
result = qa({"question": query, "chat_history" : chat_history})
|
| 80 |
|
|
|
|
| 81 |
source_docs = result["source_documents"]
|
| 82 |
+
file_names = get_file(source_docs)
|
| 83 |
+
#file_name = os.path.basename(source_docs[0].metadata['source'])
|
| 84 |
+
file_name = ', '.join([f"{x}" for x in file_names[:3]])
|
| 85 |
+
|
| 86 |
+
# print("History : ", history)
|
| 87 |
+
# print("\n Chat_his : ", chat_history)
|
| 88 |
|
| 89 |
+
return result["answer"] + "\n\nSources : " + file_name
|
| 90 |
|
| 91 |
|
| 92 |
iface = gr.ChatInterface(
|
| 93 |
fn=chat_query,
|
| 94 |
+
#title=" --: Conversational BOT for Model-TS :----- ",
|
| 95 |
description="""-- Welcome to the Language Model trained on `Model Technical Specifications` of SS-Engg. Dept.\n\n
|
| 96 |
-- The Model tries to answer the Query based on TS, GTR & Specific Requirements. \n\n
|
| 97 |
-- For precise reply, please input `Specific Keywords` in your Query. \n\n """,
|
|
|
|
| 107 |
|
| 108 |
)
|
| 109 |
|
| 110 |
+
Title= "# --: Conversational BOT for Model-TS :-- "
|
| 111 |
|
| 112 |
|
| 113 |
with gr.Blocks(css="style.css", fill_height=True) as demo:
|
| 114 |
with gr.Row():
|
| 115 |
with gr.Column(scale=1):
|
| 116 |
+
gr.Image("Chatbot.png", width=50, show_download_button = False, show_label = False, show_share_button = False )
|
| 117 |
with gr.Column(scale=10):
|
| 118 |
gr.Markdown(Title)
|
| 119 |
+
with gr.Column(scale=1):
|
| 120 |
+
gr.Image("PG Logo.png", width=50, show_download_button = False, show_label = False, show_share_button = False )
|
| 121 |
|
| 122 |
iface.render()
|
| 123 |
|