File size: 1,578 Bytes
301bfcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
import gradio as gr
from groq import Groq
from transformers import TextStreamer

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",
    )
    
    streamer = TextStreamer(client=client)

    response = ""
    for chunk in chat_completion.choices[0].message.content:
        response += chunk
        streamer.write(response)  

    return response

custom_css = """
body {
    background-color: #f4f4f4;
    font-family: 'Arial', sans-serif;
    color: #333;
}

h1 {
    color: #007bff;
}

.gradio-container {
    border-radius: 15px;
    padding: 20px;
    background-color: white;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

input[type="text"] {
    border-radius: 10px;
    border: 1px solid #ccc;
    padding: 10px;
    width: 100%;
}

button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
}

button:hover {
    background-color: #0056b3;
}
"""


iface = gr.Interface(
    fn=generate_response,
    inputs=gr.inputs.Textbox(lines=2, placeholder="یه چی بپرس"),
    outputs="text",
    title="💬 Parviz Chatbot",
    description="زنده باد",
    css=custom_css,
    theme="default",
    layout="vertical",
    allow_flagging="never"
)

iface.launch()