File size: 1,431 Bytes
48f1c4e
 
0d938e7
 
 
8500758
 
9d4e9b7
8500758
48f1c4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
from groq import Groq
import gradio as gr
import os



client = Groq(
    api_key=os.environ.get("GROQ_KEY"),
)

# Function to generate a response based on user input
def get_response_from_llama(prompt):
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": prompt}],
        model="llama3-8b-8192",
    )
    return chat_completion.choices[0].message.content

# Create the chat interface
with gr.Blocks() as demo:
    gr.Markdown("# 🦙 LLaMA Chatbot")
    gr.Markdown("### Enter a prompt below to chat with the LLaMA model!")

    # Chatbox to show conversation
    chatbot = gr.Chatbot()

    # Input text box
    with gr.Row():
        with gr.Column(scale=10):
            txt = gr.Textbox(
                show_label=False,
                placeholder="Type your message...",
            )
        with gr.Column(scale=1, min_width=100):
            send_btn = gr.Button("Send")

    def user(message, history):
        return "", history + [[message, None]]

    def bot(history):
        response = get_response_from_llama(history[-1][0])
        history[-1][1] = response
        return history

    # Linking components together
    txt.submit(user, [txt, chatbot], [txt, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )
    send_btn.click(user, [txt, chatbot], [txt, chatbot], queue=False).then(
        bot, chatbot, chatbot
    )

demo.launch(share=True)