rishiraj commited on
Commit
4c0c0ee
1 Parent(s): a238577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -37,7 +37,7 @@ def load_image_from_url(image_url: str) -> Image:
37
 
38
  def search(url):
39
  image = load_image_from_url(url)
40
- response = model.generate_content([image,"what is shown in this image?"])
41
  return response.text
42
 
43
  def format_prompt(message, history):
@@ -67,7 +67,9 @@ def generate(
67
 
68
  image = extract_image_urls(prompt)
69
  if image:
70
- prompt = prompt.replace(image, search(image))
 
 
71
  formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
72
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
73
  output = ""
@@ -122,13 +124,7 @@ additional_inputs=[
122
  )
123
  ]
124
 
125
- examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
126
- ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
127
- ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
128
- ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
129
- ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
130
- ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
131
- ]
132
 
133
  gr.ChatInterface(
134
  fn=generate,
 
37
 
38
  def search(url):
39
  image = load_image_from_url(url)
40
+ response = model.generate_content([image,"Describe what is shown in this image."])
41
  return response.text
42
 
43
  def format_prompt(message, history):
 
67
 
68
  image = extract_image_urls(prompt)
69
  if image:
70
+ image_description = "Image Description: " + search(image)
71
+ prompt = prompt.replace(image, image_description)
72
+ print(prompt)
73
  formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
74
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
75
  output = ""
 
124
  )
125
  ]
126
 
127
+ examples=[["What are they doing here https://upload.wikimedia.org/wikipedia/commons/3/38/Two_dancers.jpg ?", None, None, None, None, None]]
 
 
 
 
 
 
128
 
129
  gr.ChatInterface(
130
  fn=generate,