Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
CHANGED
@@ -1,23 +1,26 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
-
from PIL import Image
|
4 |
-
from langchain.tools import BaseTool
|
5 |
-
import torch
|
6 |
-
from transformers import BlipProcessor, BlipForConditionalGeneration
|
7 |
from langchain.agents import load_tools
|
8 |
from langchain.agents import initialize_agent
|
9 |
-
from langchain.
|
|
|
|
|
10 |
from langchain.chat_models import AzureChatOpenAI
|
11 |
-
from langchain.prompts import PromptTemplate
|
12 |
-
from langchain.chains import LLMChain
|
13 |
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
|
|
|
|
|
|
14 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
|
22 |
image_to_text_model = "Salesforce/blip-image-captioning-large"
|
23 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
@@ -27,6 +30,7 @@ processor = BlipProcessor.from_pretrained(image_to_text_model)
|
|
27 |
|
28 |
|
29 |
def describeImage(image_url):
|
|
|
30 |
image_object = Image.open(image_url).convert('RGB')
|
31 |
# image
|
32 |
inputs = processor(image_object, return_tensors="pt").to(device)
|
@@ -97,4 +101,4 @@ with gr.Blocks() as demo:
|
|
97 |
submit_btn = gr.Button('提交', variant="primary")
|
98 |
submit_btn.click(image_to_txt, inputs=[image_url, user_input], outputs=output)
|
99 |
|
100 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from langchain.agents import load_tools
|
2 |
from langchain.agents import initialize_agent
|
3 |
+
from langchain.agents import AgentType
|
4 |
+
from langchain.llms import OpenAI
|
5 |
+
# from langchain.chat_models import ChatOpenAI
|
6 |
from langchain.chat_models import AzureChatOpenAI
|
|
|
|
|
7 |
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
|
8 |
+
import os
|
9 |
+
from langchain.tools import BaseTool
|
10 |
+
import torch
|
11 |
from transformers import BlipProcessor, BlipForConditionalGeneration
|
12 |
+
from transformers.models.oneformer.modeling_oneformer import OneFormerModelOutput
|
13 |
+
import requests
|
14 |
+
from PIL import Image
|
15 |
+
import gradio as gr
|
16 |
+
from langchain.chains import LLMChain
|
17 |
+
from langchain.prompts import PromptTemplate
|
18 |
|
19 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
20 |
+
OPENAI_API_BASE = os.getenv("OPENAI_API_BASE")
|
21 |
+
DEP_NAME = os.getenv("deployment_name")
|
22 |
+
llm = AzureChatOpenAI(deployment_name=DEP_NAME, openai_api_base=OPENAI_API_BASE, openai_api_key=OPENAI_API_KEY,
|
23 |
+
openai_api_version="2023-03-15-preview", model_name="gpt-3.5-turbo")
|
24 |
|
25 |
image_to_text_model = "Salesforce/blip-image-captioning-large"
|
26 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
30 |
|
31 |
|
32 |
def describeImage(image_url):
|
33 |
+
# image_object = Image.open(requests.get(image_url, stream=True).raw).convert('RGB')
|
34 |
image_object = Image.open(image_url).convert('RGB')
|
35 |
# image
|
36 |
inputs = processor(image_object, return_tensors="pt").to(device)
|
|
|
101 |
submit_btn = gr.Button('提交', variant="primary")
|
102 |
submit_btn.click(image_to_txt, inputs=[image_url, user_input], outputs=output)
|
103 |
|
104 |
+
demo.launch()
|