Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -60,7 +60,7 @@ demo = gr.ChatInterface(
|
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
-
demo.launch()
|
64 |
#!pip install -U "transformers==4.40.0" --upgrade
|
65 |
#!pip install -i https://pypi.org/simple/ bitsandbytes
|
66 |
#!pip install accelerate
|
@@ -164,4 +164,52 @@ with gr.Blocks() as demo:
|
|
164 |
generate, inputs =[chatbot,],outputs = chatbot,)
|
165 |
|
166 |
demo.queue()
|
167 |
-
demo.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
|
62 |
if __name__ == "__main__":
|
63 |
+
demo.launch()
|
64 |
#!pip install -U "transformers==4.40.0" --upgrade
|
65 |
#!pip install -i https://pypi.org/simple/ bitsandbytes
|
66 |
#!pip install accelerate
|
|
|
164 |
generate, inputs =[chatbot,],outputs = chatbot,)
|
165 |
|
166 |
demo.queue()
|
167 |
+
demo.launch(debug=True)'''
|
168 |
+
|
169 |
+
import os
|
170 |
+
from groq import Groq
|
171 |
+
import gradio as gr
|
172 |
+
|
173 |
+
client = Groq(api_key = os.environ.get("GROQ_API_KEY"), )
|
174 |
+
|
175 |
+
system_prompt = {
|
176 |
+
"role": "system",
|
177 |
+
"content":
|
178 |
+
"You are a useful assistant. I would appreciate it if you reply with efficient answers. "
|
179 |
+
}
|
180 |
+
|
181 |
+
async def chat_groq(message, history):
|
182 |
+
|
183 |
+
messages = [system_prompt]
|
184 |
+
|
185 |
+
for msg in history:
|
186 |
+
messages.append({"role": "user", "content": str(msg[0])})
|
187 |
+
messages.append({"role": "assistant", "content": str(msg[1])})
|
188 |
+
|
189 |
+
messages.append({"role": "user", "content": str (message)})
|
190 |
+
|
191 |
+
response_content = ''
|
192 |
+
|
193 |
+
stream = client.chat.completions.create(
|
194 |
+
model="llama3-8b-8192",
|
195 |
+
messages=messages,
|
196 |
+
max_tokens=1024,
|
197 |
+
temperature=1.3,
|
198 |
+
stream=True
|
199 |
+
)
|
200 |
+
|
201 |
+
for chunk in stream:
|
202 |
+
content = chunk.choices[0].delta.content
|
203 |
+
if content:
|
204 |
+
response_content += chunk. choices[0].delta.content
|
205 |
+
yield response_content
|
206 |
+
|
207 |
+
with gr. Blocks(theme=gr.themes.Monochrome(), fill_height=True) as demo:
|
208 |
+
gr.ChatInterface(chat_groq,
|
209 |
+
clear_btn=None,
|
210 |
+
undo_btn=None,
|
211 |
+
retry_btn=None,
|
212 |
+
)
|
213 |
+
|
214 |
+
demo.queue()
|
215 |
+
demo.launch()
|