Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,6 +104,11 @@ from huggingface_hub import hf_hub_download
|
|
| 104 |
# logger.info(f'Received input: {input_text}')
|
| 105 |
# return "Output: " + input_text
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# def get_render_cameras(batch_size=1, M=120, radius=2.5, elevation=10.0, is_flexicubes=False):
|
| 109 |
# """
|
|
@@ -590,15 +595,15 @@ def build_caption_anything_with_models(args, api_key="", captioner=None, sam_mod
|
|
| 590 |
|
| 591 |
def validate_api_key(api_key):
|
| 592 |
api_key = str(api_key).strip()
|
| 593 |
-
print(api_key)
|
| 594 |
try:
|
| 595 |
test_llm = ChatOpenAI(model_name="gpt-4o", temperature=0, openai_api_key=api_key)
|
| 596 |
-
print("test_llm")
|
| 597 |
response = test_llm([HumanMessage(content='Hello')])
|
| 598 |
-
print(response)
|
| 599 |
return True
|
| 600 |
except Exception as e:
|
| 601 |
-
print(f"API key validation failed: {e}")
|
| 602 |
return False
|
| 603 |
|
| 604 |
|
|
@@ -607,23 +612,23 @@ def init_openai_api_key(api_key=""):
|
|
| 607 |
text_refiner = None
|
| 608 |
visual_chatgpt = None
|
| 609 |
if api_key and len(api_key) > 30:
|
| 610 |
-
print(api_key)
|
| 611 |
if validate_api_key(api_key):
|
| 612 |
try:
|
| 613 |
# text_refiner = build_text_refiner(args.text_refiner, args.device, args, api_key)
|
| 614 |
# assert len(text_refiner.llm('hi')) > 0 # test
|
| 615 |
text_refiner = None
|
| 616 |
-
print("text refiner")
|
| 617 |
visual_chatgpt = ConversationBot(shared_chatbot_tools, api_key=api_key)
|
| 618 |
except Exception as e:
|
| 619 |
-
print(f"Error initializing TextRefiner or ConversationBot: {e}")
|
| 620 |
text_refiner = None
|
| 621 |
visual_chatgpt = None
|
| 622 |
else:
|
| 623 |
-
print("Invalid API key.")
|
| 624 |
else:
|
| 625 |
-
print("API key is too short.")
|
| 626 |
-
print(text_refiner)
|
| 627 |
openai_available = text_refiner is not None
|
| 628 |
if visual_chatgpt:
|
| 629 |
|
|
|
|
| 104 |
# logger.info(f'Received input: {input_text}')
|
| 105 |
# return "Output: " + input_text
|
| 106 |
|
| 107 |
+
import sys
|
| 108 |
+
|
| 109 |
+
# 设置无缓冲输出
|
| 110 |
+
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', buffering=1)
|
| 111 |
+
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', buffering=1)
|
| 112 |
|
| 113 |
# def get_render_cameras(batch_size=1, M=120, radius=2.5, elevation=10.0, is_flexicubes=False):
|
| 114 |
# """
|
|
|
|
| 595 |
|
| 596 |
def validate_api_key(api_key):
|
| 597 |
api_key = str(api_key).strip()
|
| 598 |
+
print(api_key, flush=True)
|
| 599 |
try:
|
| 600 |
test_llm = ChatOpenAI(model_name="gpt-4o", temperature=0, openai_api_key=api_key)
|
| 601 |
+
print("test_llm", flush=True)
|
| 602 |
response = test_llm([HumanMessage(content='Hello')])
|
| 603 |
+
print(response, flush=True)
|
| 604 |
return True
|
| 605 |
except Exception as e:
|
| 606 |
+
print(f"API key validation failed: {e}", flush=True)
|
| 607 |
return False
|
| 608 |
|
| 609 |
|
|
|
|
| 612 |
text_refiner = None
|
| 613 |
visual_chatgpt = None
|
| 614 |
if api_key and len(api_key) > 30:
|
| 615 |
+
print(api_key, flush=True)
|
| 616 |
if validate_api_key(api_key):
|
| 617 |
try:
|
| 618 |
# text_refiner = build_text_refiner(args.text_refiner, args.device, args, api_key)
|
| 619 |
# assert len(text_refiner.llm('hi')) > 0 # test
|
| 620 |
text_refiner = None
|
| 621 |
+
print("text refiner", flush=True)
|
| 622 |
visual_chatgpt = ConversationBot(shared_chatbot_tools, api_key=api_key)
|
| 623 |
except Exception as e:
|
| 624 |
+
print(f"Error initializing TextRefiner or ConversationBot: {e}", flush=True)
|
| 625 |
text_refiner = None
|
| 626 |
visual_chatgpt = None
|
| 627 |
else:
|
| 628 |
+
print("Invalid API key.", flush=True)
|
| 629 |
else:
|
| 630 |
+
print("API key is too short.", flush=True)
|
| 631 |
+
print(text_refiner, flush=True)
|
| 632 |
openai_available = text_refiner is not None
|
| 633 |
if visual_chatgpt:
|
| 634 |
|