rbn2008k commited on
Commit
c989b7d
·
verified ·
1 Parent(s): f6d3ff5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -105,15 +105,31 @@ def inference_calling_idefics(image_path, question=""):
105
  return "Error: Invalid image or unable to encode image."
106
 
107
  image_info = f"data:image/png;base64,{image_base64}"
108
- prompt = f"{system_prompt}\n![]({image_info})\n{question}\n\n"
109
-
110
  try:
111
- response = client.text_generation(
112
- prompt,
113
- max_new_tokens=512,
114
- do_sample=True,
115
- temperature=0.2
116
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  return response
118
  except Exception as e:
119
  print(f"Error in inference call: {e}")
 
105
  return "Error: Invalid image or unable to encode image."
106
 
107
  image_info = f"data:image/png;base64,{image_base64}"
108
+ prompt = f'Describe this image without question mark. {question}'
109
+
110
  try:
111
+ response = ""
112
+ for message in client.chat_completion(
113
+ model=image_model,
114
+ messages=[
115
+ {
116
+ "role": "system",
117
+ "content": [
118
+ {"type": "text", "text": system_prompt},
119
+ ],
120
+ },
121
+ {
122
+ "role": "user",
123
+ "content": [
124
+ {"type": "image_url", "image_url": {"url": image_info}},
125
+ {"type": "text", "text": prompt},
126
+ ],
127
+ }
128
+ ],
129
+ max_tokens=2048,
130
+ stream=True,
131
+ ):
132
+ response += message.choices[0].delta.content
133
  return response
134
  except Exception as e:
135
  print(f"Error in inference call: {e}")