Update app.py
Browse files
app.py
CHANGED
|
@@ -78,36 +78,84 @@ By adhering to these rules and utilizing the provided examples as guidelines, we
|
|
| 78 |
### Assistant:
|
| 79 |
"""
|
| 80 |
|
| 81 |
-
def get_response(prompt, model_choice):
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
chat_completion = client.chat.completions.create(
|
| 87 |
messages=[
|
| 88 |
{
|
| 89 |
"role": "user",
|
| 90 |
-
"content": f"You are helpful Interior design AI assistant named Vinci based on the
|
| 91 |
-
caption:{SYSTEM_PROMPT_TEMPLATE}, Please keep your answer concise",
|
| 92 |
}
|
| 93 |
],
|
| 94 |
model=model_choice,
|
| 95 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
return chat_completion.choices[0].message.content
|
| 99 |
-
|
| 100 |
-
# Define the Gradio interface inputs including a Radio component for model selection
|
| 101 |
iface = gr.Interface(
|
| 102 |
fn=get_response,
|
| 103 |
inputs=[
|
| 104 |
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 105 |
-
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
],
|
| 107 |
-
outputs=gr.TextArea(label="Answer"),
|
| 108 |
title="Vinci 2.0 Using Groq Test",
|
| 109 |
description="Hi I am Vinci, your interior design Assistant. Ask any question and select a model to get a response from the Groq chat model."
|
| 110 |
)
|
| 111 |
|
| 112 |
# Launch the app
|
| 113 |
-
iface.launch()
|
|
|
|
| 78 |
### Assistant:
|
| 79 |
"""
|
| 80 |
|
| 81 |
+
# def get_response(prompt, model_choice):
|
| 82 |
+
# client = Groq(
|
| 83 |
+
# api_key=GROQ_API_KEY,
|
| 84 |
+
# )
|
| 85 |
+
# # Create a chat completion with the user's question and selected model
|
| 86 |
+
# chat_completion = client.chat.completions.create(
|
| 87 |
+
# messages=[
|
| 88 |
+
# {
|
| 89 |
+
# "role": "user",
|
| 90 |
+
# "content": f"You are helpful Interior design AI assistant named Vinci based on the provoided caption below please answer the following:{prompt}\n \
|
| 91 |
+
# caption:{SYSTEM_PROMPT_TEMPLATE}, Please keep your answer concise",
|
| 92 |
+
# }
|
| 93 |
+
# ],
|
| 94 |
+
# model=model_choice,
|
| 95 |
+
# )
|
| 96 |
+
|
| 97 |
+
# # Extract and return the response
|
| 98 |
+
# return chat_completion.choices[0].message.content
|
| 99 |
+
|
| 100 |
+
# # Define the Gradio interface inputs including a Radio component for model selection
|
| 101 |
+
# iface = gr.Interface(
|
| 102 |
+
# fn=get_response,
|
| 103 |
+
# inputs=[
|
| 104 |
+
# gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 105 |
+
# gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768")
|
| 106 |
+
# ],
|
| 107 |
+
# outputs=gr.TextArea(label="Answer"),
|
| 108 |
+
# title="Vinci 2.0 Using Groq Test",
|
| 109 |
+
# description="Hi I am Vinci, your interior design Assistant. Ask any question and select a model to get a response from the Groq chat model."
|
| 110 |
+
# )
|
| 111 |
+
|
| 112 |
+
# # Launch the app
|
| 113 |
+
# iface.launch()
|
| 114 |
+
def get_response(prompt, model_choice, chat_history):
|
| 115 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 116 |
+
|
| 117 |
+
# Append the new user prompt to the chat history
|
| 118 |
+
if chat_history:
|
| 119 |
+
chat_history += f"\nUser: {prompt}"
|
| 120 |
+
else:
|
| 121 |
+
chat_history = f"User: {prompt}"
|
| 122 |
+
|
| 123 |
+
# Create a chat completion with the user's question, selected model, and the chat history
|
| 124 |
chat_completion = client.chat.completions.create(
|
| 125 |
messages=[
|
| 126 |
{
|
| 127 |
"role": "user",
|
| 128 |
+
"content": f"You are helpful Interior design AI assistant named Vinci based on the provided caption below please answer the following:{prompt}\n \
|
| 129 |
+
caption:{SYSTEM_PROMPT_TEMPLATE}, Please keep your answer concise. {chat_history}",
|
| 130 |
}
|
| 131 |
],
|
| 132 |
model=model_choice,
|
| 133 |
)
|
| 134 |
+
|
| 135 |
+
# Extract the model response
|
| 136 |
+
model_response = chat_completion.choices[0].message.contents
|
| 137 |
+
|
| 138 |
+
# Update the chat history with the model's response
|
| 139 |
+
updated_chat_history = chat_history + f"\nVinci: {model_response}"
|
| 140 |
+
|
| 141 |
+
# Return the model response and the updated chat history
|
| 142 |
+
return model_response, updated_chat_history
|
| 143 |
|
| 144 |
+
# Define the Gradio interface inputs, including a hidden State input for maintaining the chat history
|
|
|
|
|
|
|
|
|
|
| 145 |
iface = gr.Interface(
|
| 146 |
fn=get_response,
|
| 147 |
inputs=[
|
| 148 |
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 149 |
+
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768"),
|
| 150 |
+
gr.State() # This will keep the chat history
|
| 151 |
+
],
|
| 152 |
+
outputs=[
|
| 153 |
+
gr.TextArea(label="Answer"),
|
| 154 |
+
gr.State() # This will output the updated chat history
|
| 155 |
],
|
|
|
|
| 156 |
title="Vinci 2.0 Using Groq Test",
|
| 157 |
description="Hi I am Vinci, your interior design Assistant. Ask any question and select a model to get a response from the Groq chat model."
|
| 158 |
)
|
| 159 |
|
| 160 |
# Launch the app
|
| 161 |
+
iface.launch()
|