dat257 commited on
Commit
6ced035
·
verified ·
1 Parent(s): 5bba1c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -25
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import logging
2
- import gradio as gr
3
  from transformers import pipeline
4
  import os
5
- import torch
6
  from huggingface_hub import login
7
  from fastapi import FastAPI, Request
8
  from fastapi.responses import JSONResponse
@@ -52,28 +50,6 @@ async def api_answer(request: Request):
52
  logging.error(f"API error: {e}")
53
  return JSONResponse({"error": str(e)}, status_code=500)
54
 
55
- # (Tạm thời comment Gradio để kiểm tra API)
56
- """
57
- with gr.Blocks() as demo:
58
- gr.Markdown("# AgriBot: Hỏi đáp nông nghiệp")
59
- gr.Markdown("Nhập câu hỏi và ngữ cảnh để nhận câu trả lời về nông nghiệp.")
60
-
61
- with gr.Row():
62
- question_input = gr.Textbox(label="Câu hỏi", placeholder="Nhập câu hỏi của bạn...")
63
- context_input = gr.Textbox(label="Ngữ cảnh", placeholder="Nhập ngữ cảnh liên quan...")
64
- output = gr.Textbox(label="Câu trả lời")
65
- submit_btn = gr.Button("Gửi")
66
- submit_btn.click(fn=gradio_answer, inputs=[question_input, context_input], outputs=output)
67
-
68
- def run_gradio():
69
- logging.info("Starting Gradio...")
70
- demo.launch(server_name="0.0.0.0", server_port=7860, share=False, show_error=True, ssr_mode=False)
71
-
72
- if __name__ == "__main__":
73
- gradio_thread = threading.Thread(target=run_gradio)
74
- gradio_thread.start()
75
- """
76
-
77
  if __name__ == "__main__":
78
  logging.info("Starting FastAPI...")
79
- uvicorn.run(app, host="0.0.0.0", port=80) # Spaces sẽ tự xử cổng
 
1
  import logging
 
2
  from transformers import pipeline
3
  import os
 
4
  from huggingface_hub import login
5
  from fastapi import FastAPI, Request
6
  from fastapi.responses import JSONResponse
 
50
  logging.error(f"API error: {e}")
51
  return JSONResponse({"error": str(e)}, status_code=500)
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  if __name__ == "__main__":
54
  logging.info("Starting FastAPI...")
55
+ uvicorn.run(app, host="0.0.0.0", port=8000) # Sử dụng cổng khác để test local, Spaces sẽ tự chọn cổng