File size: 1,467 Bytes
c09738a
 
8b9fb2f
c09738a
 
 
 
8b9fb2f
c09738a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b9fb2f
c09738a
8b9fb2f
 
c09738a
 
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
import gradio
from groq import Groq

# Initialize the Groq client with your API key
client = Groq(
    api_key="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"
)

# Initialize message prompt
def initialize_messages():
    return [{
        "role": "system",
        "content": """You are an assistant that provides answers to FAQs regarding any flights or travel assistance."""
    }]

messages_prmt = initialize_messages()

# Custom chatbot function
def customLLMBot(user_input, history):
    global messages_prmt

    messages_prmt.append({"role": "user", "content": user_input})

    response = client.chat.completions.create(
        messages=messages_prmt,
        model="llama3-8b-8192",
    )

    print(response)  # Optional: Debugging
    LLM_reply = response.choices[0].message.content
    messages_prmt.append({"role": "assistant", "content": LLM_reply})

    return LLM_reply

# Gradio interface
iface = gradio.ChatInterface(
    customLLMBot,
    chatbot=gradio.Chatbot(height=500),
    textbox=gradio.Textbox(
        placeholder="Need help with flight bookings, visa info, travel insurance, or destination tips? Ask me anything! "),
    title="FAQ ChatBot",
    description="Chat bot for FAQ service in travel assistance",
    theme="soft",
    examples=[
        "hi",
        "When is the next flight to Bangalore from Cochin?",
        "How much does it cost?"
    ],
    submit_btn=True
)

# Launch the interface
iface.launch(share=True)