GIGAParviz commited on
Commit
301bfcd
·
verified ·
1 Parent(s): b4e2519

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from groq import Groq
3
+ from transformers import TextStreamer
4
+
5
+ client = Groq(
6
+ api_key=("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"),
7
+ )
8
+
9
+ def generate_response(input_text):
10
+ chat_completion = client.chat.completions.create(
11
+ messages=[
12
+ {
13
+ "role": "user",
14
+ "content": input_text,
15
+ }
16
+ ],
17
+ model="llama3-8b-8192",
18
+ )
19
+
20
+ streamer = TextStreamer(client=client)
21
+
22
+ response = ""
23
+ for chunk in chat_completion.choices[0].message.content:
24
+ response += chunk
25
+ streamer.write(response)
26
+
27
+ return response
28
+
29
+ custom_css = """
30
+ body {
31
+ background-color: #f4f4f4;
32
+ font-family: 'Arial', sans-serif;
33
+ color: #333;
34
+ }
35
+
36
+ h1 {
37
+ color: #007bff;
38
+ }
39
+
40
+ .gradio-container {
41
+ border-radius: 15px;
42
+ padding: 20px;
43
+ background-color: white;
44
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
45
+ }
46
+
47
+ input[type="text"] {
48
+ border-radius: 10px;
49
+ border: 1px solid #ccc;
50
+ padding: 10px;
51
+ width: 100%;
52
+ }
53
+
54
+ button {
55
+ background-color: #007bff;
56
+ color: white;
57
+ border: none;
58
+ padding: 10px 20px;
59
+ border-radius: 10px;
60
+ cursor: pointer;
61
+ font-size: 16px;
62
+ }
63
+
64
+ button:hover {
65
+ background-color: #0056b3;
66
+ }
67
+ """
68
+
69
+
70
+ iface = gr.Interface(
71
+ fn=generate_response,
72
+ inputs=gr.inputs.Textbox(lines=2, placeholder="یه چی بپرس"),
73
+ outputs="text",
74
+ title="💬 Parviz Chatbot",
75
+ description="زنده باد",
76
+ css=custom_css,
77
+ theme="default",
78
+ layout="vertical",
79
+ allow_flagging="never"
80
+ )
81
+
82
+ iface.launch()