Spaces:
Sleeping
Sleeping
| 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) | |