Sayed121 commited on
Commit
fd2d211
·
verified ·
1 Parent(s): 7ad7109

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -32
app.py CHANGED
@@ -111,49 +111,38 @@ By adhering to these rules and utilizing the provided examples as guidelines, we
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
- # Update the Gradio interface definition
146
  iface = gr.Interface(
147
  fn=get_response,
148
  inputs=[
149
  gr.Textbox(lines=2, placeholder="Enter your question here..."),
150
- gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection", value="mixtral-8x7b-32768"),
151
- gr.State() # This will keep the chat history
152
  ],
153
  outputs=[
154
  gr.TextArea(label="Answer"),
155
- gr.State() # This will output the updated chat history
156
- ],
157
- title="Vinci 2.0 Using Groq Test",
158
- 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."
159
- )
 
111
 
112
  # # Launch the app
113
  # iface.launch()
114
+ def get_response(prompt, model_choice, chat_history=None): # Default `chat_history` to None if not provided
115
  client = Groq(api_key=GROQ_API_KEY)
116
+
117
+ if chat_history is None:
118
+ chat_history = "User: " + prompt
 
119
  else:
120
+ chat_history += "\nUser: " + prompt
121
+
 
122
  chat_completion = client.chat.completions.create(
123
+ messages=[{
124
+ "role": "user",
125
+ "content": f"Your prompt: {prompt}\n\nChat History:\n{chat_history}"
126
+ }],
 
 
 
127
  model=model_choice,
128
  )
129
+
130
+ model_response = chat_completion.choices[0].message.content
131
+ updated_chat_history = chat_history + "\nVinci: " + model_response
132
+
 
 
 
 
133
  return model_response, updated_chat_history
134
 
 
 
135
  iface = gr.Interface(
136
  fn=get_response,
137
  inputs=[
138
  gr.Textbox(lines=2, placeholder="Enter your question here..."),
139
+ gr.Radio(choices=["mixtral-8x7b-32768", "llama2-70b-4096"], label="Model Selection"),
140
+ gr.State()
141
  ],
142
  outputs=[
143
  gr.TextArea(label="Answer"),
144
+ gr.State()
145
+ ]
146
+ )
147
+
148
+ iface.launch()