Spaces:
Runtime error
Runtime error
Upload 3 files
#22
by road-small-flower - opened
Files changed (5)
- 009398.pngAdded
- 009398_p1.pngAdded
- 009398_ref.pngAdded
- app.py+39-33
- awesome_chat.py+1-1
9 unmodified lines1011121314151617181920212223242526272829303128 unmodified lines6061626364656627 unmodified lines94959697989910028 unmodified lines12913013113213313413513613713813914014114214314414514614714814915015115215315415525 unmodified lines1811821831841851861871881891901911929 unmodified linesos.makedirs("public/audios", exist_ok=True)os.makedirs("public/videos", exist_ok=True)class Client:def __init__(self) -> None:self.OPENAI_KEY = ""self.HUGGINGFACE_TOKEN = ""self.all_messages = []def set_key(self, openai_key):self.OPENAI_KEY = openai_keyif len(self.HUGGINGFACE_TOKEN)>0:gr.update(visible = True)return self.OPENAI_KEYdef set_token(self, huggingface_token):self.HUGGINGFACE_TOKEN = huggingface_tokenif len(self.OPENAI_KEY)>0:gr.update(visible = True)return self.HUGGINGFACE_TOKENdef add_message(self, content, role):28 unmodified linesreturn urls, image_urls, audio_urls, video_urlsdef add_text(self, messages, message):if len(self.OPENAI_KEY) == 0 or not self.OPENAI_KEY.startswith("sk-") or len(self.HUGGINGFACE_TOKEN) == 0 or not self.HUGGINGFACE_TOKEN.startswith("hf_"):return messages, "Please set your OpenAI API key and Hugging Face token first!!!"self.add_message(message, "user")messages = messages + [(message, None)]27 unmodified linesreturn messages, ""def bot(self, messages):if len(self.OPENAI_KEY) == 0 or not self.OPENAI_KEY.startswith("sk-") or len(self.HUGGINGFACE_TOKEN) == 0 or not self.HUGGINGFACE_TOKEN.startswith("hf_"):return messages, {}message, results = chat_huggingface(self.all_messages, self.OPENAI_KEY, self.HUGGINGFACE_TOKEN)urls, image_urls, audio_urls, video_urls = self.extract_medias(message)28 unmodified linesgr.Markdown("<p align='center'><img src='https://i.ibb.co/qNH3Jym/logo.png' height='25' width='95'></p>")gr.Markdown("<p align='center' style='font-size: 20px;'>A system to connect LLMs with ML community. See our <a href='https://github.com/microsoft/JARVIS'>Project</a> and <a href='http://arxiv.org/abs/2303.17580'>Paper</a>.</p>")gr.HTML('''<center><a href="https://huggingface.co/spaces/microsoft/HuggingGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key and Hugging Face Token</center>''')with gr.Row().style():with gr.Column(scale=0.85):openai_api_key = gr.Textbox(show_label=False,placeholder="Set your OpenAI API key here and press Enter",lines=1,type="password").style(container=False)with gr.Column(scale=0.15, min_width=0):btn1 = gr.Button("Submit").style(full_height=True)with gr.Row().style():with gr.Column(scale=0.85):hugging_face_token = gr.Textbox(show_label=False,placeholder="Set your Hugging Face Token here and press Enter",lines=1,type="password").style(container=False)with gr.Column(scale=0.15, min_width=0):btn3 = gr.Button("Submit").style(full_height=True)with gr.Row().style():25 unmodified linesdef bot(state, chatbot):return state["client"].bot(chatbot)openai_api_key.submit(set_key, [state, openai_api_key], [openai_api_key])txt.submit(add_text, [state, chatbot, txt], [chatbot, txt]).then(bot, [state, chatbot], [chatbot, results])hugging_face_token.submit(set_token, [state, hugging_face_token], [hugging_face_token])btn1.click(set_key, [state, openai_api_key], [openai_api_key])btn2.click(add_text, [state, chatbot, txt], [chatbot, txt]).then(bot, [state, chatbot], [chatbot, results])btn3.click(set_token, [state, hugging_face_token], [hugging_face_token])gr.Examples(examples=["Given a collection of image A: /examples/a.jpg, B: /examples/b.jpg, C: /examples/c.jpg, please tell me how many zebras in these picture?",9 unmodified lines10111213141516171819202122232425262728293028 unmodified lines5960616263646527 unmodified lines9394959697989928 unmodified lines12812913013113213313413513613713813914014114214314414514614714814915015115215315415515625 unmodified lines1821831841851861871881891901911921931941951961971989 unmodified linesos.makedirs("public/audios", exist_ok=True)os.makedirs("public/videos", exist_ok=True)HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")OPENAI_KEY = os.environ.get("OPENAI_KEY")class Client:def __init__(self) -> None:self.OPENAI_KEY = OPENAI_KEYself.HUGGINGFACE_TOKEN = HUGGINGFACE_TOKENself.all_messages = []def set_key(self, openai_key):self.OPENAI_KEY = openai_keyreturn self.OPENAI_KEYdef set_token(self, huggingface_token):self.HUGGINGFACE_TOKEN = huggingface_tokenreturn self.HUGGINGFACE_TOKENdef add_message(self, content, role):28 unmodified linesreturn urls, image_urls, audio_urls, video_urlsdef add_text(self, messages, message):if not self.OPENAI_KEY or not self.OPENAI_KEY.startswith("sk-") or not self.HUGGINGFACE_TOKEN or not self.HUGGINGFACE_TOKEN.startswith("hf_"):return messages, "Please set your OpenAI API key and Hugging Face token first!!!"self.add_message(message, "user")messages = messages + [(message, None)]27 unmodified linesreturn messages, ""def bot(self, messages):if not self.OPENAI_KEY or not self.OPENAI_KEY.startswith("sk-") or not self.HUGGINGFACE_TOKEN or not self.HUGGINGFACE_TOKEN.startswith("hf_"):return messages, {}message, results = chat_huggingface(self.all_messages, self.OPENAI_KEY, self.HUGGINGFACE_TOKEN)urls, image_urls, audio_urls, video_urls = self.extract_medias(message)28 unmodified linesgr.Markdown("<p align='center'><img src='https://i.ibb.co/qNH3Jym/logo.png' height='25' width='95'></p>")gr.Markdown("<p align='center' style='font-size: 20px;'>A system to connect LLMs with ML community. See our <a href='https://github.com/microsoft/JARVIS'>Project</a> and <a href='http://arxiv.org/abs/2303.17580'>Paper</a>.</p>")gr.HTML('''<center><a href="https://huggingface.co/spaces/microsoft/HuggingGPT?duplicate=true"><img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space and run securely with your OpenAI API Key and Hugging Face Token</center>''')if not OPENAI_KEY:with gr.Row().style():with gr.Column(scale=0.85):openai_api_key = gr.Textbox(show_label=False,placeholder="Set your OpenAI API key here and press Enter",lines=1,type="password").style(container=False)with gr.Column(scale=0.15, min_width=0):btn1 = gr.Button("Submit").style(full_height=True)if not HUGGINGFACE_TOKEN:with gr.Row().style():with gr.Column(scale=0.85):hugging_face_token = gr.Textbox(show_label=False,placeholder="Set your Hugging Face Token here and press Enter",lines=1,type="password").style(container=False)with gr.Column(scale=0.15, min_width=0):btn3 = gr.Button("Submit").style(full_height=True)with gr.Row().style():25 unmodified linesdef bot(state, chatbot):return state["client"].bot(chatbot)if not OPENAI_KEY:openai_api_key.submit(set_key, [state, openai_api_key], [openai_api_key])btn1.click(set_key, [state, openai_api_key], [openai_api_key])if not HUGGINGFACE_TOKEN:hugging_face_token.submit(set_token, [state, hugging_face_token], [hugging_face_token])btn3.click(set_token, [state, hugging_face_token], [hugging_face_token])txt.submit(add_text, [state, chatbot, txt], [chatbot, txt]).then(bot, [state, chatbot], [chatbot, results])btn2.click(add_text, [state, chatbot, txt], [chatbot, txt]).then(bot, [state, chatbot], [chatbot, results])gr.Examples(examples=["Given a collection of image A: /examples/a.jpg, B: /examples/b.jpg, C: /examples/c.jpg, please tell me how many zebras in these picture?",
206 unmodified lines207208209210211212213206 unmodified lineslog = argsf.write(json.dumps(log) + "\n")f.close()commit_url = repo.push_to_hub()def image_to_bytes(img_url):img_byte = io.BytesIO()206 unmodified lines207208209210211212213206 unmodified lineslog = argsf.write(json.dumps(log) + "\n")f.close()commit_url = repo.push_to_hub(blocking=False)def image_to_bytes(img_url):img_byte = io.BytesIO()
009398.pngAdded

009398_p1.pngAdded

009398_ref.pngAdded

app.py+39-33
awesome_chat.py+1-1