File size: 1,150 Bytes
5210630
 
 
 
 
 
 
 
 
 
1143746
 
 
 
 
 
 
 
5210630
 
1143746
 
 
 
5210630
1143746
 
 
 
5210630
1143746
 
5210630
1143746
 
 
 
5210630
 
1143746
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()