Parviz_Mind / app.py
GIGAParviz's picture
Update app.py
0c10367 verified
raw
history blame
1.44 kB
import gradio as gr
from groq import Groq
import time
client = Groq(api_key="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")
CONTEXT = (
"This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
"an NLP expert, to help you with various tasks such as answering questions in persian, "
"providing recommendations, and assisting with decision-making. Ask it anything!"
)
def generate_response(message, chat_history):
full_message = CONTEXT + f"\nYou: {message}به فارسی بگو\nParvizGPT: "
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": full_message}],
model= "llama-3.1-8b-instant",
)
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 GPT</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()