Update utils.py
Browse files
utils.py
CHANGED
|
@@ -68,11 +68,6 @@ LLM_CHAIN_PROMPT = PromptTemplate(input_variables = ["question"],
|
|
| 68 |
RAG_CHAIN_PROMPT = PromptTemplate(input_variables = ["context", "question"],
|
| 69 |
template = rag_template)
|
| 70 |
|
| 71 |
-
################################################
|
| 72 |
-
#Plattform Keys aus den Secrets holen zu diesem Space
|
| 73 |
-
HUGGINGFACEHUB_API_TOKEN = os.getenv("HF_ACCESS_READ")
|
| 74 |
-
OAI_API_KEY=os.getenv("OPENAI_API_KEY")
|
| 75 |
-
HEADERS = {"Authorization": f"Bearer {HUGGINGFACEHUB_API_TOKEN}"}
|
| 76 |
|
| 77 |
################################################
|
| 78 |
#Pfad, wo Docs/Bilder/Filme abgelegt werden können - lokal, also hier im HF Space (sonst auf eigenem Rechner)
|
|
@@ -492,43 +487,7 @@ def create_picture(history, prompt):
|
|
| 492 |
image = Image.open(response2.raw)
|
| 493 |
return image
|
| 494 |
|
| 495 |
-
|
| 496 |
-
#ein hochgeladenes Bild so vorbereiten, dass OpenAI API es annehmen kann und bearbeiten
|
| 497 |
-
#muss ein base64 Bils sein und header und payload entsprechend konfigurieren
|
| 498 |
-
def process_image(image_path, prompt):
|
| 499 |
-
# Convert image to base64
|
| 500 |
-
with open(image_path, "rb") as image_file:
|
| 501 |
-
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
# Prepare the data for the API request (specific to the API you're using)
|
| 505 |
-
headers = {
|
| 506 |
-
"Content-Type": "application/json",
|
| 507 |
-
"Authorization": f"Bearer {OAI_API_KEY}"
|
| 508 |
-
}
|
| 509 |
-
|
| 510 |
-
payload = {
|
| 511 |
-
"model": MODEL_NAME_IMAGE,
|
| 512 |
-
"messages": [
|
| 513 |
-
{
|
| 514 |
-
"role": "user",
|
| 515 |
-
"content": [
|
| 516 |
-
{
|
| 517 |
-
"type": "text",
|
| 518 |
-
"text": prompt
|
| 519 |
-
},
|
| 520 |
-
{
|
| 521 |
-
"type": "image_url",
|
| 522 |
-
"image_url": {
|
| 523 |
-
"url": f"data:image/jpeg;base64,{encoded_string}"
|
| 524 |
-
}
|
| 525 |
-
}
|
| 526 |
-
]
|
| 527 |
-
}
|
| 528 |
-
],
|
| 529 |
-
"max_tokens": 300
|
| 530 |
-
}
|
| 531 |
-
return headers, payload
|
| 532 |
|
| 533 |
###################################################
|
| 534 |
#zur Zeit nicht im Gebrauch
|
|
|
|
| 68 |
RAG_CHAIN_PROMPT = PromptTemplate(input_variables = ["context", "question"],
|
| 69 |
template = rag_template)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
################################################
|
| 73 |
#Pfad, wo Docs/Bilder/Filme abgelegt werden können - lokal, also hier im HF Space (sonst auf eigenem Rechner)
|
|
|
|
| 487 |
image = Image.open(response2.raw)
|
| 488 |
return image
|
| 489 |
|
| 490 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
|
| 492 |
###################################################
|
| 493 |
#zur Zeit nicht im Gebrauch
|