Spaces:
Sleeping
Sleeping
Rename Image_generation.py to Image_text_generation.py
Browse files
Image_generation.py → Image_text_generation.py
RENAMED
|
@@ -5,11 +5,12 @@ from datetime import datetime
|
|
| 5 |
import PIL.Image
|
| 6 |
from google import genai
|
| 7 |
from google.genai import types
|
|
|
|
| 8 |
from imgurpython import ImgurClient
|
| 9 |
|
| 10 |
genai_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
| 11 |
|
| 12 |
-
class
|
| 13 |
def __init__(self, imgur):
|
| 14 |
# 初始化 Imgur 客戶端
|
| 15 |
self.imgur_client = imgur
|
|
@@ -74,3 +75,15 @@ class ImageGenerator:
|
|
| 74 |
except Exception as e:
|
| 75 |
print(f"圖片上傳失敗: {e}")
|
| 76 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import PIL.Image
|
| 6 |
from google import genai
|
| 7 |
from google.genai import types
|
| 8 |
+
import httpx
|
| 9 |
from imgurpython import ImgurClient
|
| 10 |
|
| 11 |
genai_client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
| 12 |
|
| 13 |
+
class Image_text_Generator:
|
| 14 |
def __init__(self, imgur):
|
| 15 |
# 初始化 Imgur 客戶端
|
| 16 |
self.imgur_client = imgur
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
print(f"圖片上傳失敗: {e}")
|
| 77 |
return None
|
| 78 |
+
|
| 79 |
+
def generate_txt_with_gemini(self, prompt,doc_url):
|
| 80 |
+
doc_data = httpx.get(doc_url).content
|
| 81 |
+
|
| 82 |
+
response = client.models.generate_content(
|
| 83 |
+
model="gemini-1.5-flash",
|
| 84 |
+
contents=[
|
| 85 |
+
types.Part.from_bytes(data=doc_data, mime_type='application/pdf',),prompt]
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return response.text
|
| 89 |
+
|