File size: 1,439 Bytes
720745c
 
 
26d467b
0c10367
 
 
 
 
 
 
26d467b
720745c
0c10367
 
720745c
0c10367
 
720745c
 
26d467b
720745c
 
 
26d467b
720745c
26d467b
720745c
 
26d467b
720745c
 
26d467b
720745c
26d467b
720745c
0c10367
 
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
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()