iShare commited on
Commit
b16b9b6
·
1 Parent(s): 08feaf0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -20
main.py CHANGED
@@ -6,7 +6,7 @@ from langchain.chains.summarize import load_summarize_chain
6
  #https://python.langchain.com/docs/use_cases/summarization
7
  from langchain import HuggingFaceHub
8
  from huggingface_hub import InferenceClient
9
- #from bs4 import BeautifulSoup
10
  import requests
11
  import sys
12
 
@@ -30,27 +30,24 @@ app = FastAPI()
30
  @app.post('/')
31
  async def home_api(request: Request):
32
  data = await request.json()
33
- user_query = data['user_question']
34
- print(user_query)
35
  return {"Message": "FastAPI Home API Deploy Success on HF"}
36
 
37
  @app.post('/api/chat')
38
  async def chat(request: Request):
39
  data = await request.json()
40
- user_query = data['user_question']
41
- print(user_query)
42
- if user_query.strip() != "":
43
- try:
44
- loader = WebBaseLoader(user_query)
45
- print(user_query)
46
- docs = loader.load()
47
- result = chain.run(docs)
48
- print("AI Summarization: " + result)
49
- #return {'response': result} #FastAPI方式下,这个返回形式,有问题?
50
- return JSONResponse({'response': result})
51
- except Exception as e:
52
- err_msg = "Wrong URL or URL not parsable."
53
- print(err_msg)
54
- raise HTTPException(status_code=400, detail=err_msg)
55
- else:
56
- raise HTTPException(status_code=400, detail="Invalid user question")
 
6
  #https://python.langchain.com/docs/use_cases/summarization
7
  from langchain import HuggingFaceHub
8
  from huggingface_hub import InferenceClient
9
+ from bs4 import BeautifulSoup
10
  import requests
11
  import sys
12
 
 
30
  @app.post('/')
31
  async def home_api(request: Request):
32
  data = await request.json()
33
+ target_url = data['target_url']
34
+ print(target_url)
35
  return {"Message": "FastAPI Home API Deploy Success on HF"}
36
 
37
  @app.post('/api/chat')
38
  async def chat(request: Request):
39
  data = await request.json()
40
+ target_url = data['target_url']
41
+ print(target_url)
42
+ try:
43
+ loader = WebBaseLoader(target_url)
44
+ print(target_url)
45
+ docs = loader.load()
46
+ result = chain.run(docs)
47
+ print("AI Summarization: " + result)
48
+ #return {'response': result} #FastAPI方式下,这个返回形式,有问题?
49
+ return JSONResponse({'response': result})
50
+ except Exception as e:
51
+ err_msg = "Wrong URL or URL not parsable."
52
+ print(err_msg)
53
+ raise HTTPException(status_code=400, detail=err_msg)