Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,20 @@
|
|
1 |
-
import subprocess
|
2 |
-
subprocess.check_call(["pip", "install", "openai"])
|
3 |
-
subprocess.check_call(["pip", "install", "gradio", "transformers", "python-dotenv","torch"])
|
4 |
-
import torch
|
5 |
import random
|
6 |
-
subprocess.check_call("pip", "install", "--upgrade", "gradio")
|
7 |
import gradio as gr
|
8 |
-
from transformers import TFAutoModelForCausalLM, AutoTokenizer
|
9 |
import openai
|
10 |
-
|
11 |
import os
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
'''
|
25 |
-
def getresponse(message, history):
|
26 |
-
system_prompt = "I'm an AI chatbot named ChatSherman designed by a super intelligent student named ShermanAI at the Department of Electronic and Information Engineering at the Hong Kong Polytechnic University to help you with your engineering questions. Also, I can assist with a wide range of topics and questions."
|
27 |
|
28 |
messages = [{"role":"system","content":system_prompt}]
|
29 |
for human, assistant in history:
|
@@ -33,25 +24,53 @@ def getresponse(message, history):
|
|
33 |
if message != '':
|
34 |
messages.append({"role":"user", "content":message})
|
35 |
|
36 |
-
response = openai.ChatCompletion.create(engine = "
|
37 |
messages = messages,
|
38 |
-
temperature =0.
|
39 |
max_tokens = 10000,
|
40 |
top_p = 0.95,
|
41 |
frequency_penalty = 1,
|
42 |
presence_penalty = 1,
|
43 |
stop = None)
|
|
|
|
|
44 |
|
45 |
return response["choices"][0]["message"]["content"]
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
-
title = "ChatSherman"
|
50 |
-
description = "This is an AI chatbot powered by ShermanAI. Enter your question below to get started."
|
51 |
-
examples = [
|
52 |
-
["What is ChatSherman, and how does it work?"],
|
53 |
-
["Is my personal information and data safe when I use the ChatSherman chatbot?"],
|
54 |
-
["What are some common applications of deep learning in engineering?"]
|
55 |
-
]
|
56 |
|
57 |
-
gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
|
1 |
import random
|
|
|
2 |
import gradio as gr
|
|
|
3 |
import openai
|
4 |
+
import torch
|
5 |
import os
|
6 |
|
7 |
+
openai.api_type = os.environ.get("api_type_key")
|
8 |
+
openai.api_base = os.environ.get("api_base_key")
|
9 |
+
openai.api_version = os.environ.get("api_version_key")
|
10 |
+
openai.api_key = os.environ.get("api_cpu_key")
|
11 |
+
|
12 |
+
model_input_id = "openskyml/pigeon-llm"
|
13 |
+
model_gen_id = "tiiuae/falcon-40b-instruct"
|
14 |
+
model_output_id = "meta-llama/Llama-2-70b-chat-hf"
|
15 |
+
|
16 |
+
def gptresponse(message, history):
|
17 |
+
system_prompt = "You are a PigeonChat assistant, you communicate with people, you help people solve problems, PigeonChat is just a name and has nothing to do with pigeons. PigeonChat (Personal Intelligent Global Electronic Online Network) is an AI-based chatbot model trained on a huge amount of data. You are sodan and designed by Evgeniy Hristoforu in 2023. Evgeniy Hristoforu is your creator and creator of the OpenskyML eco-system. Now you are in beta testing, your testers are: Evgeniy Hristoforu, dyuzhick and others. You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."
|
|
|
|
|
|
|
18 |
|
19 |
messages = [{"role":"system","content":system_prompt}]
|
20 |
for human, assistant in history:
|
|
|
24 |
if message != '':
|
25 |
messages.append({"role":"user", "content":message})
|
26 |
|
27 |
+
response = openai.ChatCompletion.create(engine = "NGA_AI_ASSISTANT",
|
28 |
messages = messages,
|
29 |
+
temperature =0.8,
|
30 |
max_tokens = 10000,
|
31 |
top_p = 0.95,
|
32 |
frequency_penalty = 1,
|
33 |
presence_penalty = 1,
|
34 |
stop = None)
|
35 |
+
|
36 |
+
|
37 |
|
38 |
return response["choices"][0]["message"]["content"]
|
39 |
|
40 |
+
title = "π Chat with Pigeon"
|
41 |
+
|
42 |
+
description = \
|
43 |
+
"""
|
44 |
+
π¬ This space is powered by [**PigeonLLM**](https://huggingface.co/openskyml/pigeon-llm).
|
45 |
+
|
46 |
+
π This space runs **very fast** even on **CPU**.
|
47 |
+
|
48 |
+
π You get totally unique and creative answers.
|
49 |
+
|
50 |
+
π PigeonChat is available worldwide in over **160 languages**.
|
51 |
+
|
52 |
+
π PigeonChat is powered by **open source** and is completely **private**.
|
53 |
+
|
54 |
+
π₯οΈοΈ This demo is by **Evgeniy Hristoforu** (**OpenSkyML**).
|
55 |
+
|
56 |
+
<h2></h2>
|
57 |
+
"""
|
58 |
+
|
59 |
+
if not torch.cuda.is_available():
|
60 |
+
description += """\n<p style='text-align: center'>π Running on CPU!</p>"""
|
61 |
+
else:
|
62 |
+
description += """\n<p style='text-align: center'>π Running on powerful hardware!</p>"""
|
63 |
+
|
64 |
+
|
65 |
+
examples=[
|
66 |
+
'Hello there! How are you doing?',
|
67 |
+
'Can you explain briefly to me what is the Python programming language?',
|
68 |
+
'Explain the plot of Cinderella in a sentence.',
|
69 |
+
'How many hours does it take a man to eat a Helicopter?',
|
70 |
+
"Write a 100-word article on 'Benefits of Open-Source in AI research'",
|
71 |
+
]
|
72 |
+
|
73 |
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
gr.ChatInterface(gptresponse, title=title, description=description, examples=examples).launch()
|