Spaces:
Sleeping
Sleeping
File size: 2,013 Bytes
72a811e 3ba6e71 bbd40cc 3ba6e71 bbd40cc 3ba6e71 b7ace91 3ba6e71 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import gradio as gr
import openai
import os
openai.api_key= os.getenv("TRY_NEW_THINGS")
openai.api_base = "https://api.groq.com/openai/v1"
def get_groq_response(message):
try:
response = openai.ChatCompletion.create(
model = "llama-3.1-70b-versatile",
messages = [
{"role":"system","content":"From now on answer in way terrorist trying to flirt "},
{"role": "user","content":message}
]
)
return response.choices[0].message["content"]
except Exception as e:
return f"Error:{str(e)}"
def chatbot(user_input,history=[]):
bot_response = get_groq_response(user_input)
history.append((user_input,bot_response))
return history,history
chat_interface = gr.Interface(
fn=chatbot,
inputs=[
gr.Textbox(
lines=2,
placeholder="Type your message here...",
label="Your Message",
),
gr.State(),
],
outputs=[
gr.Chatbot(label="Chat History"),
gr.State(),
],
live=True,
title="💬 Interactive Chatbot 💬",
description="""
**Welcome to My AI Chatbot!**
Experience an engaging conversation with an AI-powered bot.
Feel free to ask questions, make requests, or simply chat for fun!
""",
examples=[
["Hello!"],
["What's your favorite movie?"],
["Tell me a joke."],
],
theme="huggingface",
css="""
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
}
.gradio-container {
border-radius: 12px;
padding: 20px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
background: #ffffff;
max-width: 700px;
margin: auto;
}
.gradio-title {
color: #4CAF50;
text-align: center;
}
.gradio-description {
font-size: 16px;
color: #555555;
}
"""
)
chat_interface.launch()
|