GIGAParviz commited on
Commit
0c10367
·
verified ·
1 Parent(s): 8e13636

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -96
app.py CHANGED
@@ -1,46 +1,21 @@
1
-
2
- # import gradio as gr
3
- # from groq import Groq
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
- # return chat_completion.choices[0].message.content
20
-
21
-
22
- # iface = gr.Interface(
23
- # fn=generate_response,
24
- # inputs=gr.Textbox(label="ورودی" , lines=2, placeholder="اینجا یه چی بپرس... "),
25
- # outputs=gr.Textbox(label="جواب"),
26
- # title="💬 Parviz GPT",
27
- # description="زنده باد",
28
- # theme="dark",
29
- # allow_flagging="never"
30
-
31
- # )
32
- # iface.launch()
33
-
34
  import gradio as gr
35
  from groq import Groq
36
  import time
37
 
38
- client = Groq(api_key="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")
 
 
 
 
 
 
39
 
40
  def generate_response(message, chat_history):
 
 
41
  chat_completion = client.chat.completions.create(
42
- messages=[{"role": "user", "content": message}],
43
- model="llama3-8b-8192",
44
  )
45
  bot_message = chat_completion.choices[0].message.content
46
 
@@ -50,7 +25,6 @@ def generate_response(message, chat_history):
50
 
51
  yield chat_history + [(message, bot_message)]
52
 
53
-
54
  with gr.Blocks() as demo:
55
  gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1><p style='text-align: center; color: #e0e0e0;'>زنده باد</p>")
56
 
@@ -60,62 +34,5 @@ with gr.Blocks() as demo:
60
  msg.submit(generate_response, [msg, chatbot], chatbot)
61
 
62
  clear = gr.ClearButton([msg, chatbot])
63
- demo.launch()
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
- # import gradio as gr
78
- # import torch
79
- # from transformers import AutoTokenizer, AutoModelForCausalLM
80
-
81
- # tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0", use_fast=True)
82
- # model = AutoModelForCausalLM.from_pretrained(
83
- # "universitytehran/PersianMind-v1.0",
84
- # torch_dtype=torch.bfloat16
85
- # ).to("cpu")
86
-
87
- # CONTEXT = (
88
- # "This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
89
- # "an NLP expert, to help you with various tasks such as answering questions, "
90
- # "providing recommendations, and assisting with decision-making. Ask it anything!"
91
- # )
92
- # pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu")
93
-
94
- # def generate_response(message, chat_history):
95
- # prompt = torch.cat(
96
- # [pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
97
- # dim=1
98
- # )
99
-
100
- # with torch.no_grad():
101
- # outputs = model.generate(
102
- # prompt,
103
- # max_new_tokens=32,
104
- # temperature=0.6,
105
- # top_k=20,
106
- # top_p=0.8,
107
- # do_sample=True
108
- # )
109
-
110
- # result = tokenizer.decode(outputs[0], skip_special_tokens=True)
111
- # response = result.split("ParvizGPT:")[-1].strip()
112
- # return chat_history + [(message, response)]
113
-
114
- # with gr.Blocks() as demo:
115
- # gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1>")
116
- # chatbot = gr.Chatbot(label="Response")
117
- # msg = gr.Textbox(label="Input", placeholder="Ask your question...", lines=1)
118
- # msg.submit(generate_response, [msg, chatbot], chatbot)
119
- # gr.ClearButton([msg, chatbot])
120
-
121
- # demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from groq import Groq
3
  import time
4
 
5
+ client = Groq(api_key="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")
6
+
7
+ CONTEXT = (
8
+ "This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
9
+ "an NLP expert, to help you with various tasks such as answering questions in persian, "
10
+ "providing recommendations, and assisting with decision-making. Ask it anything!"
11
+ )
12
 
13
  def generate_response(message, chat_history):
14
+ full_message = CONTEXT + f"\nYou: {message}به فارسی بگو\nParvizGPT: "
15
+
16
  chat_completion = client.chat.completions.create(
17
+ messages=[{"role": "user", "content": full_message}],
18
+ model= "llama-3.1-8b-instant",
19
  )
20
  bot_message = chat_completion.choices[0].message.content
21
 
 
25
 
26
  yield chat_history + [(message, bot_message)]
27
 
 
28
  with gr.Blocks() as demo:
29
  gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1><p style='text-align: center; color: #e0e0e0;'>زنده باد</p>")
30
 
 
34
  msg.submit(generate_response, [msg, chatbot], chatbot)
35
 
36
  clear = gr.ClearButton([msg, chatbot])
37
+
38
+ demo.launch()