Spaces:
Running
Running
File size: 1,059 Bytes
dec332b |
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 35 36 37 38 |
import streamlit as st
import os, base64, requests
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def get_transcribed_text(base64_image):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {OPENAI_API_KEY}"
}
payload = {
"model": "gpt-4-vision-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "transcribe the image into text for me."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
],
"max_tokens": 300
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
transcribed_msg = response.json()["choices"][0]["message"]["content"]
return transcribed_msg |