GIGAParviz commited on
Commit
7839ba4
·
verified ·
1 Parent(s): f824d07

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -50
app.py DELETED
@@ -1,50 +0,0 @@
1
- import gradio as gr
2
- import torch
3
- from transformers import AutoTokenizer, AutoModelForCausalLM
4
-
5
- tokenizer = AutoTokenizer.from_pretrained("universitytehran/PersianMind-v1.0")
6
- model = AutoModelForCausalLM.from_pretrained(
7
- "universitytehran/PersianMind-v1.0",
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
-
17
- pretokenized_context = tokenizer(CONTEXT, return_tensors="pt").input_ids.to("cpu")
18
-
19
-
20
- def generate_response(message, chat_history):
21
-
22
-
23
- prompt = torch.cat(
24
- [pretokenized_context, tokenizer("\nYou: " + message + "\nParvizGPT: ", return_tensors="pt").input_ids.to("cpu")],
25
- dim=1
26
- )
27
-
28
- with torch.no_grad():
29
- outputs = model.generate(
30
- prompt,
31
- max_new_tokens=64,
32
- do_sample=True,
33
- temperature=0.7,
34
- top_k=40,
35
- top_p=0.9
36
- )
37
-
38
- result = tokenizer.decode(outputs[0], skip_special_tokens=True)
39
- response = result.split("ParvizGPT:")[-1].strip()
40
- return chat_history + [(message, response)]
41
-
42
-
43
- with gr.Blocks() as demo:
44
- gr.Markdown("<h1 style='text-align: center;'>💬 Parviz GPT</h1>")
45
- chatbot = gr.Chatbot(label="Response")
46
- msg = gr.Textbox(label="Input", placeholder="Ask your question...", lines=1)
47
- msg.submit(generate_response, [msg, chatbot], chatbot)
48
- gr.ClearButton([msg, chatbot])
49
-
50
- demo.launch()