| import os |
| import gradio as gr |
| from groq import Groq |
|
|
| |
| |
| |
|
|
| |
| |
| |
| |
|
|
| client = Groq( |
| api_key=os.environ.get("Keypass") |
| ) |
|
|
| |
| |
| |
|
|
| def chatbot_response(message, history): |
| try: |
| messages = [] |
|
|
| |
| for human, assistant in history: |
| messages.append({"role": "user", "content": human}) |
| messages.append({"role": "assistant", "content": assistant}) |
|
|
| |
| messages.append({"role": "user", "content": message}) |
|
|
| completion = client.chat.completions.create( |
| model="llama3-70b-8192", |
| messages=messages, |
| temperature=0.7, |
| max_tokens=1024, |
| ) |
|
|
| response = completion.choices[0].message.content |
| return response |
|
|
| except Exception as e: |
| return f"Error: {str(e)}" |
|
|
|
|
| |
| |
| |
|
|
| demo = gr.ChatInterface( |
| fn=chatbot_response, |
| title="π Groq AI Chatbot", |
| description="Chatbot powered by Groq API + LLaMA3", |
| theme="soft" |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch() |