Parviz_Mind / app.py
GIGAParviz's picture
Upload app.py
a11b57b verified
raw
history blame
2.71 kB
# import gradio as gr
# from groq import Groq
# client = Groq(
# api_key=("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"),
# )
# def generate_response(input_text):
# chat_completion = client.chat.completions.create(
# messages=[
# {
# "role": "user",
# "content": input_text,
# }
# ],
# model="llama3-8b-8192",
# )
# return chat_completion.choices[0].message.content
# custom_css = """
# body {
# background-color: #f5f5f5;
# font-family: 'Arial', sans-serif;
# color: #333;
# }
# .gradio-container {
# border-radius: 12px;
# padding: 20px;
# background-color: #ffffff;
# box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
# }
# input[type="text"], textarea {
# border-radius: 10px;
# border: 1px solid #ddd;
# padding: 12px;
# width: 100%;
# font-size: 14px;
# color: #333;
# background-color: #f9f9f9;
# }
# button {
# background-color: #007bff;
# color: white;
# border: none;
# padding: 12px 24px;
# border-radius: 10px;
# cursor: pointer;
# font-size: 14px;
# font-weight: bold;
# }
# button:hover {
# background-color: #0056b3;
# }
# h1 {
# font-weight: 600;
# color: #333;
# }
# textarea {
# resize: none;
# }
# """
# iface = gr.Interface(
# fn=generate_response,
# inputs=gr.Textbox(label="ورودی" , lines=2, placeholder="اینجا یه چی بپرس... "),
# outputs=gr.Textbox(label="جواب"),
# title="💬 Parviz Chatbot",
# description="زنده باد",
# theme="dark",
# allow_flagging="never"
# )
# iface.launch()
import gradio as gr
from groq import Groq
import time
client = Groq(api_key="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")
def generate_response(message, chat_history):
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": message}],
model="llama3-8b-8192",
)
bot_message = chat_completion.choices[0].message.content
for i in range(0, len(bot_message), 10):
yield chat_history + [(message, bot_message[:i + 10])]
time.sleep(0.1)
yield chat_history + [(message, bot_message)]
with gr.Blocks() as demo:
gr.Markdown("<h1 style='text-align: center;'>💬 Parviz Chatbot</h1><p style='text-align: center; color: #e0e0e0;'>زنده باد</p>")
chatbot = gr.Chatbot(label="جواب")
msg = gr.Textbox(label="ورودی", placeholder="اینجا یه چی بپرس... ", lines=1)
msg.submit(generate_response, [msg, chatbot], chatbot)
clear = gr.ClearButton([msg, chatbot])
demo.launch()