Update app.py
Browse files
app.py
CHANGED
|
@@ -639,7 +639,6 @@ def build_demo():
|
|
| 639 |
)
|
| 640 |
|
| 641 |
return demo
|
| 642 |
-
|
| 643 |
# --- API endpoint: /chat ---
|
| 644 |
|
| 645 |
def http_api_infer(question: str, request: gr.Request):
|
|
@@ -680,14 +679,15 @@ def http_api_infer(question: str, request: gr.Request):
|
|
| 680 |
return f"❌ Error: {str(e)}"
|
| 681 |
|
| 682 |
|
| 683 |
-
|
| 684 |
-
|
| 685 |
fn=http_api_infer,
|
| 686 |
inputs=[gr.Textbox(label="Question")],
|
| 687 |
outputs="text",
|
| 688 |
api_name="/chat"
|
| 689 |
)
|
| 690 |
|
|
|
|
| 691 |
if __name__ == "__main__":
|
| 692 |
parser = argparse.ArgumentParser()
|
| 693 |
parser.add_argument("--host", type=str, default="0.0.0.0")
|
|
@@ -698,19 +698,16 @@ if __name__ == "__main__":
|
|
| 698 |
args = parser.parse_args()
|
| 699 |
logger.info(f"args: {args}")
|
| 700 |
|
| 701 |
-
#
|
| 702 |
ui_demo = build_demo()
|
| 703 |
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
# Serve both under tabs — API tab will be invisible in browser but callable
|
| 708 |
demo = gr.TabbedInterface(
|
| 709 |
interface_list=[ui_demo, api_interface],
|
| 710 |
tab_names=["UI", "API"]
|
| 711 |
)
|
| 712 |
|
| 713 |
-
#
|
| 714 |
demo.queue(api_open=True).launch(
|
| 715 |
server_name=args.host,
|
| 716 |
server_port=args.port,
|
|
|
|
| 639 |
)
|
| 640 |
|
| 641 |
return demo
|
|
|
|
| 642 |
# --- API endpoint: /chat ---
|
| 643 |
|
| 644 |
def http_api_infer(question: str, request: gr.Request):
|
|
|
|
| 679 |
return f"❌ Error: {str(e)}"
|
| 680 |
|
| 681 |
|
| 682 |
+
# ✅ Define the API Interface after the function is declared
|
| 683 |
+
api_interface = gr.Interface(
|
| 684 |
fn=http_api_infer,
|
| 685 |
inputs=[gr.Textbox(label="Question")],
|
| 686 |
outputs="text",
|
| 687 |
api_name="/chat"
|
| 688 |
)
|
| 689 |
|
| 690 |
+
|
| 691 |
if __name__ == "__main__":
|
| 692 |
parser = argparse.ArgumentParser()
|
| 693 |
parser.add_argument("--host", type=str, default="0.0.0.0")
|
|
|
|
| 698 |
args = parser.parse_args()
|
| 699 |
logger.info(f"args: {args}")
|
| 700 |
|
| 701 |
+
# UI block
|
| 702 |
ui_demo = build_demo()
|
| 703 |
|
| 704 |
+
# Combine UI + API endpoint
|
|
|
|
|
|
|
|
|
|
| 705 |
demo = gr.TabbedInterface(
|
| 706 |
interface_list=[ui_demo, api_interface],
|
| 707 |
tab_names=["UI", "API"]
|
| 708 |
)
|
| 709 |
|
| 710 |
+
# Launch with API access
|
| 711 |
demo.queue(api_open=True).launch(
|
| 712 |
server_name=args.host,
|
| 713 |
server_port=args.port,
|