Spaces:
Running
Running
Niki Zhang
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,8 @@ from packaging import version
|
|
| 11 |
from PIL import Image, ImageDraw
|
| 12 |
import functools
|
| 13 |
import emoji
|
| 14 |
-
from
|
|
|
|
| 15 |
from caption_anything.model import CaptionAnything
|
| 16 |
from caption_anything.utils.image_editing_utils import create_bubble_frame
|
| 17 |
from caption_anything.utils.utils import mask_painter, seg_model_map, prepare_segmenter, image_resize
|
|
@@ -513,8 +514,9 @@ def validate_api_key(api_key):
|
|
| 513 |
api_key = str(api_key).strip()
|
| 514 |
print(api_key)
|
| 515 |
try:
|
| 516 |
-
test_llm =
|
| 517 |
-
|
|
|
|
| 518 |
print(response)
|
| 519 |
return True
|
| 520 |
except Exception as e:
|
|
@@ -530,9 +532,11 @@ def init_openai_api_key(api_key=""):
|
|
| 530 |
print(api_key)
|
| 531 |
if validate_api_key(api_key):
|
| 532 |
try:
|
| 533 |
-
text_refiner = build_text_refiner(args.text_refiner, args.device, args, api_key)
|
| 534 |
-
assert len(text_refiner.llm('hi')) > 0 # test
|
| 535 |
-
|
|
|
|
|
|
|
| 536 |
except Exception as e:
|
| 537 |
print(f"Error initializing TextRefiner or ConversationBot: {e}")
|
| 538 |
text_refiner = None
|
|
@@ -543,7 +547,7 @@ def init_openai_api_key(api_key=""):
|
|
| 543 |
print("API key is too short.")
|
| 544 |
print(text_refiner)
|
| 545 |
openai_available = text_refiner is not None
|
| 546 |
-
if
|
| 547 |
|
| 548 |
global gpt_state
|
| 549 |
gpt_state=1
|
|
|
|
| 11 |
from PIL import Image, ImageDraw
|
| 12 |
import functools
|
| 13 |
import emoji
|
| 14 |
+
from langchain_community.chat_models import ChatOpenAI
|
| 15 |
+
from langchain.schema import HumanMessage
|
| 16 |
from caption_anything.model import CaptionAnything
|
| 17 |
from caption_anything.utils.image_editing_utils import create_bubble_frame
|
| 18 |
from caption_anything.utils.utils import mask_painter, seg_model_map, prepare_segmenter, image_resize
|
|
|
|
| 514 |
api_key = str(api_key).strip()
|
| 515 |
print(api_key)
|
| 516 |
try:
|
| 517 |
+
test_llm = ChatOpenAI(model_name="gpt-4o", temperature=0, openai_api_key=api_key)
|
| 518 |
+
print("test_llm")
|
| 519 |
+
response = test_llm([HumanMessage(content='Hello')])
|
| 520 |
print(response)
|
| 521 |
return True
|
| 522 |
except Exception as e:
|
|
|
|
| 532 |
print(api_key)
|
| 533 |
if validate_api_key(api_key):
|
| 534 |
try:
|
| 535 |
+
# text_refiner = build_text_refiner(args.text_refiner, args.device, args, api_key)
|
| 536 |
+
# assert len(text_refiner.llm('hi')) > 0 # test
|
| 537 |
+
text_refiner = None
|
| 538 |
+
print("text refiner")
|
| 539 |
+
visual_chatgpt = ConversationBot(shared_chatbot_tools, api_key=api_key)
|
| 540 |
except Exception as e:
|
| 541 |
print(f"Error initializing TextRefiner or ConversationBot: {e}")
|
| 542 |
text_refiner = None
|
|
|
|
| 547 |
print("API key is too short.")
|
| 548 |
print(text_refiner)
|
| 549 |
openai_available = text_refiner is not None
|
| 550 |
+
if visual_chatgpt:
|
| 551 |
|
| 552 |
global gpt_state
|
| 553 |
gpt_state=1
|