ChatBot-UI / app.py
adriiita's picture
Update app.py
1143746 verified
raw
history blame
1.15 kB
import os
import gradio as gr
from groq import Groq
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
def chat_with_groq(user_input, additional_context=None):
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": user_input,
}
],
model="llama-3.1-8b-instant",
)
return chat_completion.choices[0].message.content
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox(placeholder="Ask me any question", scale=6)
clear = gr.Button("Clear")
def user_interaction(user_input, history):
response = chat_with_groq(user_input)
history = history + [(user_input, response)]
return history, ""
msg.submit(user_interaction, [msg, chatbot], [chatbot, msg])
clear.click(lambda: None, None, chatbot)
demo.launch(title="Hey NOPE",
theme="monochrome",
description="Welcome to the world of NOPE",
examples=["Need some content Idea", "Generate some Thumbnail Text"])
if __name__ == "__main__":
demo.launch()