SFP commited on
Commit
71f1200
1 Parent(s): aedf7d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -2,18 +2,21 @@ import gradio as gr
2
  from PIL import Image
3
  import requests
4
  import base64
 
5
  import openai
6
  openai.api_key = ""
7
  openai.api_base = "https://api.deepinfra.com/v1/openai"
8
  def todataimage(file, ext):
9
- image_data_uri = "data:image/png;base64," + base64.b64encode(file)
10
- return image_data_uri
 
11
  def caption(file, ext):
 
12
  response = requests.post("https://russellc-comparing-captioning-models.hf.space/run/predict", json={
13
  "data": [
14
- todataimage(file, ext),
15
  ]}).json()
16
-
17
  data = response["data"]
18
  chat_completion = openai.ChatCompletion.create(
19
  model="meta-llama/Llama-2-70b-chat-hf",
@@ -24,5 +27,5 @@ def caption(file, ext):
24
  def image_predict(image):
25
  return caption(image, "png")
26
 
27
- iface = gr.Interface(fn=image_predict, inputs="image", outputs="label")
28
  iface.launch()
 
2
  from PIL import Image
3
  import requests
4
  import base64
5
+ import io
6
  import openai
7
  openai.api_key = ""
8
  openai.api_base = "https://api.deepinfra.com/v1/openai"
9
  def todataimage(file, ext):
10
+ buffered = io.BytesIO()
11
+ file.save(buffered, format=ext)
12
+ return "data:image/png;base64,"+base64.b64encode(buffered.getvalue()).decode("utf-8")
13
  def caption(file, ext):
14
+ datimg = todataimage(file, ext)
15
  response = requests.post("https://russellc-comparing-captioning-models.hf.space/run/predict", json={
16
  "data": [
17
+ datimg,
18
  ]}).json()
19
+ print(response)
20
  data = response["data"]
21
  chat_completion = openai.ChatCompletion.create(
22
  model="meta-llama/Llama-2-70b-chat-hf",
 
27
  def image_predict(image):
28
  return caption(image, "png")
29
 
30
+ iface = gr.Interface(image_predict, inputs=gr.Image(type="pil"), outputs="label", flagging_options=[])
31
  iface.launch()