Spaces:
Sleeping
Sleeping
Update app.py
Browse files35 unmodified lines363738394041424344454647484950515244 unmodified lines97989910010110210310439 unmodified lines14414514614714814915015115215315415515615715815935 unmodified linesprompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"inputs = processor(prompt, image, return_tensors="pt")streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)generated_text = ""thread = Thread(target=model.generate, kwargs=generation_kwargs)thread.start()buffer = ""for new_text in streamer:buffer += new_textyield bufferdef extract_text_from_webpage(html_content):soup = BeautifulSoup(html_content, 'html.parser')44 unmodified linesuser_prompt = message# Handle image processingif message["files"]:streamer = llava(message, history)yield streamerelse:functions_metadata = [{"type": "function", "function": {"name": "web_search", "description": "Search query on google", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "web search query"}}, "required": ["query"]}}},39 unmodified linesyield outputelif json_data["name"] == "image_generation":query = json_data["arguments"]["query"]gr.Info("Generating Image, Please wait...")seed = random.randint(1, 99999)query = query.replace(" ", "%20")image = f""yield imagetime.sleep(5)gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")elif json_data["name"] == "image_qna":messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You are provide with both images and captions and Your task is to answer of user with help of caption provided. Answer in human style and show emotions.<|end_header_id|>"yield llava(message, history)else:messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"for msg in history:35 unmodified lines3637383940414244 unmodified lines8788899091929394959697989910010110210339 unmodified lines14314414514614714814915015115215315415515615715815916016116216316416516616735 unmodified linesprompt = f"<|im_start|>user <image>\n{user_prompt}<|im_end|><|im_start|>assistant"inputs = processor(prompt, image, return_tensors="pt")return inputsdef extract_text_from_webpage(html_content):soup = BeautifulSoup(html_content, 'html.parser')44 unmodified linesuser_prompt = message# Handle image processingif message["files"]:inputs = llava(message, history)streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)thread = Thread(target=model.generate, kwargs=generation_kwargs)thread.start()buffer = ""for new_text in streamer:buffer += new_textyield bufferelse:functions_metadata = [{"type": "function", "function": {"name": "web_search", "description": "Search query on google", "parameters": {"type": "object", "properties": {"query": {"type": "string", "description": "web search query"}}, "required": ["query"]}}},39 unmodified linesyield outputelif json_data["name"] == "image_generation":query = json_data["arguments"]["query"]gr.Info("Generating Image, Please wait 10 sec...")seed = random.randint(1, 99999)query = query.replace(" ", "%20")image = f""yield imagetime.sleep(8)gr.Info("We are going to Update Our Image Generation Engine to more powerful ones in Next Update. ThankYou")elif json_data["name"] == "image_qna":inputs = llava(message, history)streamer = TextIteratorStreamer(processor, skip_prompt=True, **{"skip_special_tokens": True})generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=1024)thread = Thread(target=model.generate, kwargs=generation_kwargs)thread.start()buffer = ""for new_text in streamer:buffer += new_textyield bufferelse:messages = f"<|start_header_id|>system\nYou are OpenGPT 4o mini a helpful assistant made by KingNish. You answers users query like human friend. You are also Expert in every field and also learn and try to answer from contexts related to previous question. Try your best to give best response possible to user. You also try to show emotions using Emojis and reply like human, use short forms, friendly tone and emotions.<|end_header_id|>"for msg in history:
app.py+25-17