awd
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ models = {
|
|
15 |
},
|
16 |
}
|
17 |
|
18 |
-
# Chat Function
|
19 |
def chat_with_model(model_choice, user_message, chat_history, file=None):
|
20 |
if model_choice == "PDF Summarizer (T5)" and file is not None:
|
21 |
pdf_text = extract_text_from_pdf(file)
|
@@ -27,11 +27,16 @@ def chat_with_model(model_choice, user_message, chat_history, file=None):
|
|
27 |
model_info = models[model_choice]
|
28 |
client = model_info["client"]
|
29 |
|
30 |
-
# Prepare messages for the InferenceClient
|
31 |
-
messages = [
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Generate Response
|
37 |
response = ""
|
|
|
15 |
},
|
16 |
}
|
17 |
|
18 |
+
# Chat Function with Context
|
19 |
def chat_with_model(model_choice, user_message, chat_history, file=None):
|
20 |
if model_choice == "PDF Summarizer (T5)" and file is not None:
|
21 |
pdf_text = extract_text_from_pdf(file)
|
|
|
27 |
model_info = models[model_choice]
|
28 |
client = model_info["client"]
|
29 |
|
30 |
+
# Prepare messages for the InferenceClient including chat history
|
31 |
+
messages = [{"role": "system", "content": "You are a helpful assistant."}]
|
32 |
+
|
33 |
+
# Add previous conversation to the messages
|
34 |
+
for user_msg, bot_msg in chat_history:
|
35 |
+
messages.append({"role": "user", "content": user_msg})
|
36 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
37 |
+
|
38 |
+
# Add the current user message
|
39 |
+
messages.append({"role": "user", "content": user_message})
|
40 |
|
41 |
# Generate Response
|
42 |
response = ""
|