Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import torch
|
3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
-
|
5 |
-
tokenizer = AutoTokenizer.from_pretrained("HooshvareLab/gpt2-fa", use_fast=True)
|
6 |
-
model = AutoModelForCausalLM.from_pretrained(
|
7 |
-
"HooshvareLab/gpt2-fa",
|
8 |
-
torch_dtype=torch.bfloat16
|
9 |
-
).to("cpu")
|
10 |
-
|
11 |
-
CONTEXT = (
|
12 |
-
"This is a conversation with ParvizGPT. It is an artificial intelligence model designed by Amir Mahdi Parviz, "
|
13 |
-
"an NLP expert, to help you with various tasks such as answering questions, "
|
14 |
-
"providing recommendations, and assisting with decision-making. Ask it anything!"
|
15 |
-
)
|
16 |
-
pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu")
|
17 |
-
|
18 |
-
def generate_response(message, chat_history):
|
19 |
-
prompt = torch.cat(
|
20 |
-
[pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
|
21 |
-
dim=1
|
22 |
-
)
|
23 |
-
|
24 |
-
with torch.no_grad():
|
25 |
-
outputs = model.generate(
|
26 |
-
prompt,
|
27 |
-
max_new_tokens=32,
|
28 |
-
temperature=0.6,
|
29 |
-
top_k=20,
|
30 |
-
top_p=0.8,
|
31 |
-
do_sample=True
|
32 |
-
)
|
33 |
-
|
34 |
-
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
35 |
-
response = result.split("ParvizGPT:")[-1].strip()
|
36 |
-
return chat_history + [(message, response)]
|
37 |
-
|
38 |
-
with gr.Blocks() as demo:
|
39 |
-
gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1>")
|
40 |
-
chatbot = gr.Chatbot(label="Response")
|
41 |
-
msg = gr.Textbox(label="Input", placeholder="Ask your question...", lines=1)
|
42 |
-
msg.submit(generate_response, [msg, chatbot], chatbot)
|
43 |
-
gr.ClearButton([msg, chatbot])
|
44 |
-
|
45 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|