import gradio as gr import time import os qaMap = {} qaMap['receipt1.png'] = "AI: This is an image..AI: This image is likely a receipt or ticket..AI: This is a receipt from BOARDWALK restaurant on 8/16/2019 at 15:57. The check number is 312086, table number is 100, and there are 8 guests. The server's name is Kris H? and the terminal number is 31. The items ordered are: 1 Iced Tea ($3.00), 1 Nachos ($9.00), 1 Parfait ($6.00), 1 HH Sea Rum Swiz ($7.00), 1 HH Sea Rum Swiz ($7.00), 1 HH RM Honey Bee ($7.00), 1 HH Sea Rum Swiz ($7.00), 1 HH C R Manhattan ($7.00), and 1 Glass Prosecco ($10.00).." qaMap['How much was the Parfait?'] = "AI: The Parfait was $6.00." qaMap['how much was Iced tea and parfait in total?'] = "AI: The total cost of Ice tea and parfait was $9.00.." qaMap['find the menu for this restaurant'] = "AI: This question requires Bing search..AI: This is the menu for BOARDWALK restaurant. They serve breakfast, continental breakfast, seafood brunch, and lunch. They have an all-day menu with island favorites and homemade items. They also serve a rich country and delicious lobster bisque in a bread bowl or regular bowl.." qaMap['Can you do a reservation?'] = "AI: This question requires Bing search..AI: You can make a reservation at BOARDWALK restaurant by calling (714) 845-8444. You can also make a reservation on OpenTable. BOARDWALK restaurant is open from 7:00 am to 10:00 pm from Monday to Thursday and Sunday, and from 7:00 am to 11:00 pm on Friday and Saturday. The dining style is casual elegant and the cuisine is unspecified.." qaMap['face4.jpg'] = "AI: This is an image..AI: There are faces detected in this image, let me find if I know the person..AI: This image contains Emilia Clarke, Margot Robbie, Angelina Jolie, Emma Watson, Anne Hathaway, Megan Fox, Emma Stone, Jennifer Lawrence, Gal Gadot, Scarlett Johansson. They are posing for a picture.." qaMap['Who is in the top left corner of the image?'] = "AI: The person in the top left corner of the image is Angelina Jolie." qaMap['What is her most popular movie?'] = "AI: This question requires Bing search..AI: Angelina Jolie's most popular movie is Girl, Interrupted. It is the movie that garnered her first Academy Award win for acting.." qaMap['Where can I watch this movie?'] = "AI: This question requires Bing search..AI: You can watch Girl, Interrupted on Netflix.." qaMap['Can you share some link to watch?'] = "AI: This question requires Bing search..AI: You can watch Girl, Interrupted on Netflix by following this link: https://www.netflix.com/title/60024077." qaMap['money6.jpg'] = "AI: This is an image..AI: This image is likely a banknote or money..AI: This is a banknote of 500 in Bangladesh. The banknote number is 5 48683171. The banknote is in the Bengali language.." qaMap['Which country is it used?'] = "AI: This banknote is used in Bangladesh.." qaMap['How much is it in US dollar?'] = "AI: This question requires Bing search..AI: 500 BDT is equal to 4.67 USD at the rate on 2023-02-25. The exchange rate increased by 0.09% (by +$0.000009) compared to yesterday.." qaMap['pillbottlefront.png'] = "AI: This is an image..AI: This image is likely a pill bottle with labels..AI: This is a dietary supplement of NATURE'S BOUNTY Co Q-10 100mg for cardiovascular health. It comes in 75 Rapid Release Softgels.." qaMap['Is this medicine good for heart?'] = "AI: This is a subjective question and depends on individual health conditions and doctor's advice. It is recommended to consult a doctor before taking any new medicine.." qaMap['where can I buy it?'] = "AI: This question requires Bing search..AI: You can buy NATURE'S BOUNTY Co Q-10 100mg dietary supplement at Walgreens and Nature's Bounty store. The price is $57.64 for a pack of 2.." qaMap['blue_white_bird.jpg'] = "AI: This is an image..AI: This image is likely a blue bird on a branch..AI: This image does not contain any celebrities.." qaMap['change the color of bird\'s feathers from blue to red'] = "AI: Here is the updated image.. ![](/file=temp_pictures/xdecoder_edit_image/blue_white_bird_red.jpg)" qaMap['Furniture_Gateway_02.jpg'] = "AI: This is an image..AI: This image is likely a couch in a room..AI: This image does not contain any celebrities.." qaMap['make the sofa to one with leather'] = "AI: Here is the updated image.. ![](/file=temp_pictures/xdecoder_edit_image/Furniture_Gateway_02_result.jpg)" qaMap['zebras.jpg'] = "AI: This is an image..AI: This image is likely zebras walking in water..AI: This image does not contain any celebrities.." qaMap['change sky to Seattle skyline'] = "AI: Here is the updated image.. ![](/file=temp_pictures/xdecoder_edit_image/zebras_result.jpg)" qaMap['safari_rhino.mp4'] = "AI: This is a video. AI: This video is about a rhino with a large horn is walking down a road. Another rhino is following behind it, eating grass.. A rhino is seen walking down a road in this video. The rhino has a small horn on its head. It is seen walking on the road and eating grass on the side of the road.. A rhino walks down a dirt road. It's large horn is visible on its head.. A rhino walks down a road, with other rhinos on either side. It has a large horn on its head.. A rhino is seen walking on a dirt road in this video. It has a large horn on its head and is walking on all four legs. The rhino appears to be alone in the video.. A rhino walks down a dirt road and stops to eat grass in a field. Another rhino watches as it passes by.. A rhino is walking on the road and eating grass in a field.. A rhino is walking down a road in Africa, with another rhino walking beside it. The scenery is of green grass and trees.. A rhino is walking on the road and the other one is looking at it. The second rhino then walks next to the first one and looks at the camera. The first rhino then walks with a baby on the side of it. The second rhino walks with a small horn on the side of the road.. Rhinos on the move! These massive animals are usually peaceful, but can be dangerous if provoked.. A rhino and its baby are walking down a road in Africa. The rhino has a small horn, and the baby is holding a bird.. The rhinos are out for a stroll with one of them carrying a ball. Along the way, they meet a small bird that joins them on their journey.. " qaMap['Can you give me a shorter summary?'] = "AI: A rhino walks down a dirt road with another rhino following closely behind. The second rhino has a large horn, while the first rhino has a small horn. They both eat grass on the side of the road as they walk.. A rhino is walking down a dirt road with a large horn. The other rhino is looking at it.. A rhino is seen walking on a dirt road and eating grass in a field in this video.. A mother and child rhinoceros walk down a dirt path in Africa. The mother looks around protectively as the child playfully follows behind.. Two rhinos are walking down the road. One is carrying a small bird on its head, and the other is holding a ball. They are followed by a smaller rhino.. " qaMap['find the baby rhino in the video'] = "AI: The baby Rhino is at 2:05 in the video.. ![](/file=temp_pictures/xdecoder_edit_image/baby_rhino_appear.jpg)" qaMap[''] = "" qaMap[''] = "" qaMap[''] = "" # qaMap['blue_white_bird.jpg'] = def lookup(text): for key in qaMap.keys(): if text.lower().strip() == key.lower().strip(): return qaMap[key] def lookupImage(text): # remove /tmp/ replaced_tmp = text.replace('/tmp/', '').lower().strip() for key in qaMap.keys(): splitKey = key.lower().strip().split('.') if replaced_tmp.startswith(splitKey[0]) and replaced_tmp.endswith(splitKey[1]): return qaMap[key] def add_text(state, text): time.sleep(10) state = state + [("{}".format(text), "{}".format(lookup(text)))] print (state) # state = state + [(text, text + "?")] return state, state def add_image(state, image): time.sleep(8) # localFilePath = image.name # ext = localFilePath.split(".")[-1] # rest = ".".join(localFilePath.split(".")[:-1]) # removed_hash = "_".join(rest.split("_")[:-1]) # filename_only = removed_hash.split("/")[-1] # original_filename = filename_only + "." + ext if image.name.endswith('.mp4'): state = state + [(f"{image.name}", "{}".format(lookupImage(image.name)))] else: state = state + [(f"![](/file={image.name})", "{}".format(lookupImage(image.name)))] # state = state + [(f"![](/file={image.name})", f"This is an image edited![](/file={image.name})")] # state = state + [(f"![](/file={image.name})", f"This is an image editedThis is an image editedThis is an image edited![](/file={image.name})")] print (state) return state, state # with gr.Blocks(css="#chatbot .overflow-y-scroll{height:600px}") as demo: # with gr.Blocks(css="#chatbot {height:600px}") as demo: # with gr.Blocks(css="#chatbot {height: 650px; overflow: auto;}") as demo: with gr.Blocks() as demo: chatbot = gr.Chatbot(elem_id="chatbot").style(height=620) state = gr.State([]) with gr.Row(): with gr.Column(scale=0.85): txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter, or upload an image").style(container=False) with gr.Column(scale=0.15, min_width=0): btn = gr.UploadButton("🖼️", file_types=["image", "video"]) txt.submit(add_text, [state, txt], [state, chatbot]) txt.submit(lambda :"", None, txt) btn.upload(add_image, [state, btn], [state, chatbot]) demo.launch(debug=True, server_name="0.0.0.0")