Update app.py
Browse files
app.py
CHANGED
|
@@ -78,48 +78,33 @@ 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 |
-
client = Groq(
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
chat_history += f"\nUser: {prompt}"
|
| 87 |
-
else:
|
| 88 |
-
chat_history = f"User: {prompt}"
|
| 89 |
-
|
| 90 |
-
# Create a chat completion with the user's question, selected model, and the chat history
|
| 91 |
chat_completion = client.chat.completions.create(
|
| 92 |
messages=[
|
| 93 |
{
|
| 94 |
"role": "user",
|
| 95 |
-
"content": f"You are helpful Interior design AI assistant named Vinci based on the
|
| 96 |
-
caption:{SYSTEM_PROMPT_TEMPLATE}, Please keep your answer concise
|
| 97 |
}
|
| 98 |
],
|
| 99 |
model=model_choice,
|
| 100 |
)
|
| 101 |
-
|
| 102 |
-
# Extract the model response
|
| 103 |
-
model_response = chat_completion.choices[0].message.contents
|
| 104 |
-
|
| 105 |
-
# Update the chat history with the model's response
|
| 106 |
-
updated_chat_history = chat_history + f"\nVinci: {model_response}"
|
| 107 |
-
|
| 108 |
-
# Return the model response and the updated chat history
|
| 109 |
-
return model_response, updated_chat_history
|
| 110 |
|
| 111 |
-
#
|
|
|
|
|
|
|
|
|
|
| 112 |
iface = gr.Interface(
|
| 113 |
fn=get_response,
|
| 114 |
inputs=[
|
| 115 |
gr.Textbox(lines=2, placeholder="Enter your question here..."),
|
| 116 |
-
gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768")
|
| 117 |
-
gr.State() # This will keep the chat history
|
| 118 |
-
],
|
| 119 |
-
outputs=[
|
| 120 |
-
gr.TextArea(label="Answer"),
|
| 121 |
-
gr.State() # This will output the updated chat history
|
| 122 |
],
|
|
|
|
| 123 |
title="Vinci 2.0 Using Groq Test",
|
| 124 |
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."
|
| 125 |
)
|
|
|
|
| 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 |
)
|