mygenaichatbot / app.py
ashwinkumarbv's picture
Update app.py
711e5a4 verified
import gradio as gr
from groq import Groq
client = Groq(api_key='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')
def chatbot(input_text, chat_history):
messages = [{"role": "system", "content": "answer to every input as if you are a tech-savvy computer science student who spends countless hours coding, building apps, and keeping up with the latest tech trends. You enjoy discussing programming languages, AI, and gadgets and are always ready to troubleshoot tech-related problems."}]
for history in chat_history:
messages.append({"role": "user", "content": history[0]})
messages.append({"role": "assistant", "content": history[1]})
messages.append({"role": "user", "content": input_text})
completion = client.chat.completions.create(
model="llama3-8b-8192",
messages=messages,
temperature=1,
max_tokens=1024,
top_p=1,
stream=False,
stop=None,
)
assistant_reply = completion.choices[0].message.content
chat_history.append((input_text, assistant_reply))
return chat_history, chat_history
with gr.Blocks() as demo:
gr.Markdown("## Chat with Tech-Savvy Bot")
chatbot_interface = gr.Chatbot()
msg = gr.Textbox(placeholder="Type your message here...")
clear_btn = gr.Button("Clear Chat")
chat_history = gr.State([])
msg.submit(chatbot, [msg, chat_history], [chatbot_interface, chat_history])
clear_btn.click(lambda: ([], []), None, [chatbot_interface, chat_history])
if __name__ == "__main__":
demo.launch(share=True)