| | from typing import Union |
| |
|
| | from fastapi import FastAPI |
| | import asyncio |
| |
|
| | from groq import Groq, AsyncGroq |
| |
|
| | from fastapi import FastAPI, File, UploadFile |
| | from fastapi.responses import HTMLResponse |
| | import shutil |
| | import os |
| |
|
| |
|
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| |
|
| | app = FastAPI() |
| |
|
| | import google.generativeai as genai |
| | import os |
| |
|
| | genai.configure(api_key="AIzaSyBGhEOy-JYMzGtTcRjBjP51OGR168WKRFw") |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | @app.post("/upload-image/{prompt}") |
| | async def upload_image(prompt: str, file: UploadFile = File(...)): |
| | os.makedirs("uploads", exist_ok=True) |
| |
|
| |
|
| | file_location = f"uploads/{file.filename}" |
| | with open(file_location, "wb") as buffer: |
| | shutil.copyfileobj(file.file, buffer) |
| |
|
| | myfile = genai.upload_file(file_location) |
| | |
| | model = genai.GenerativeModel("gemini-1.5-pro-latest") |
| | result = model.generate_content( |
| | [myfile, "\n\n", prompt] |
| | ) |
| |
|
| | return result.text |
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|