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