Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -5,32 +5,39 @@ from gradio_client import Client
|
|
| 5 |
import mistune
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
-
app = fastapi.FastAPI(
|
| 9 |
-
docs_url='/',
|
| 10 |
-
)
|
| 11 |
|
| 12 |
@app.get("/")
|
| 13 |
def read_root():
|
| 14 |
return {"data": "Hello World"}
|
| 15 |
|
| 16 |
-
# http://localhost:8080/generate?pdfurl=https://nayankasturi.eu.org/assets/docs/latest_resume.pdf&doi=10.1145/3394486.3412865
|
| 17 |
@app.get("/generate")
|
| 18 |
async def generate(pdfurl: str, doi: str):
|
|
|
|
| 19 |
client = Client("raannakasturi/ScientryAPI")
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
"data": {
|
| 32 |
"summary": summary,
|
| 33 |
"mindmap": mindmap
|
| 34 |
}
|
| 35 |
}
|
| 36 |
-
return json.dumps(returndata)
|
|
|
|
| 5 |
import mistune
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
app = fastapi.FastAPI(docs_url='/')
|
|
|
|
|
|
|
| 9 |
|
| 10 |
@app.get("/")
|
| 11 |
def read_root():
|
| 12 |
return {"data": "Hello World"}
|
| 13 |
|
|
|
|
| 14 |
@app.get("/generate")
|
| 15 |
async def generate(pdfurl: str, doi: str):
|
| 16 |
+
# Adjust the client initialization if needed
|
| 17 |
client = Client("raannakasturi/ScientryAPI")
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
result = await asyncio.to_thread(
|
| 21 |
+
client.predict,
|
| 22 |
+
url=pdfurl,
|
| 23 |
+
id=doi,
|
| 24 |
+
access_key="scientrypass",
|
| 25 |
+
api_name="/rexplore_summarizer"
|
| 26 |
+
)
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return {"error": f"Failed to call predict API: {str(e)}"}
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
data = json.loads(result[0])
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return {"error": f"Failed to parse API response: {str(e)}"}
|
| 34 |
+
|
| 35 |
+
summary = html.unescape(mistune.html(data.get('summary', '')))
|
| 36 |
+
mindmap = data.get('mindmap', {})
|
| 37 |
+
|
| 38 |
+
return {
|
| 39 |
"data": {
|
| 40 |
"summary": summary,
|
| 41 |
"mindmap": mindmap
|
| 42 |
}
|
| 43 |
}
|
|
|