Spaces:
SFP
/
Runtime error

File size: 1,766 Bytes
fe15a96
 
5fd680d
 
71f1200
9160ce9
 
5fd680d
 
 
 
71f1200
 
 
5fd680d
71f1200
5fd680d
 
71f1200
5fd680d
71f1200
5fd680d
 
325ea2b
6c5b35d
5fd680d
 
 
a7a9bdc
5fd680d
77d1bb4
4c906a5
ce9deeb
4c906a5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import gradio as gr
from PIL import Image
import requests
import base64
import io
import os
os.system("pip install openai")
import openai
openai.api_key = ""
openai.api_base = "https://api.deepinfra.com/v1/openai"
def todataimage(file, ext):
    buffered = io.BytesIO()
    file.save(buffered, format=ext)
    return "data:image/png;base64,"+base64.b64encode(buffered.getvalue()).decode("utf-8")
def caption(file, ext):
  datimg = todataimage(file, ext)
  response = requests.post("https://russellc-comparing-captioning-models.hf.space/run/predict", json={
    "data": [
      datimg,
  ]}).json()
  print(response)
  data = response["data"]
  chat_completion = openai.ChatCompletion.create(
    model="jondurbin/airoboros-l2-70b-gpt4-1.4.1",
    messages=[{"role": "system", "content": "you will be given descriptions of one image from a varity of image captioning models with a varity of quality, what you need to do is combine them into one image caption and make that be your output, no extras words like \"here is your output\", remeber, don't take too much information from low quality, or too little from high. do NOT contain ANY text other than the description. Remember MERGE them and add details, and do NOT copy from any of the given descriptions, also, use prior knowledge to infer details."},{"role":"user", "content":"High Quality:\n"+data[1]+"\n"+data[3]+"\nMedium Quality:\n"+data[2]+"\nLow Quality\n"+data[0]}],
)

  return chat_completion.choices[0].message.content
def image_predict(image):
    return caption(image, "png")
examples = [["penguin.png"], ["stop.png"], ["stick.png"]]
title = "ImCap v1 API"
iface = gr.Interface(image_predict, inputs=gr.Image(type="pil"), outputs="label", flagging_options=[], description=description)
iface.launch()