Spaces:
Sleeping
Sleeping
shethjenil
commited on
Commit
•
5b6d38e
1
Parent(s):
eff43d0
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ from llama_index.core import StorageContext , VectorStoreIndex
|
|
3 |
from llama_index.core.base.base_retriever import BaseRetriever
|
4 |
from llama_index.core.schema import TextNode , NodeRelationship
|
5 |
from llama_index.embeddings.huggingface_api import HuggingFaceInferenceAPIEmbedding
|
6 |
-
from json import loads
|
7 |
from chromadb import EphemeralClient
|
8 |
from llama_index.vector_stores.chroma import ChromaVectorStore
|
9 |
from requests import get as reqget
|
@@ -11,7 +10,6 @@ from nest_asyncio import apply
|
|
11 |
from os import environ
|
12 |
from pickle import load as pickle_load
|
13 |
from bs4 import BeautifulSoup
|
14 |
-
from io import BytesIO
|
15 |
import flask
|
16 |
class AIBook:
|
17 |
embed_model:HuggingFaceInferenceAPIEmbedding
|
@@ -49,7 +47,7 @@ book = AIBook()
|
|
49 |
def function():
|
50 |
question = flask.request.args.get("question")
|
51 |
if question is None:
|
52 |
-
return """Please provide a question as 'https://shethjenil-apiofbookai.hf.space?question=પ્રભુ છે કે નહિ'<br>for get image by book and page https://shethjenil-apiofbookai.hf.space/getbookimage/023657/99<br>for knowing full data with page etc https://shethjenil-apiofbookai.hf.space/fulldetails?question=પ્રભુ છે કે નહિ<br>Change Token as https://shethjenil-apiofbookai.hf.space/changeToken?token=hf_<b>rgPNhjnXpLSodIphwjmRvPbvrovNYnQavj</b><br>Change srcnum as https://shethjenil-apiofbookai.hf.space/changesrcnum?srcnum=2<br><br><form action="/insert_node" method="post" enctype="multipart/form-data"><input type="file" name="file" accept=".book"><input type="submit" value="Upload Book File"></form>"""
|
53 |
if question == "":
|
54 |
return ""
|
55 |
return "\n\n".join(AIBook.nodes_to_guj(book.retrieve(AIBook.translate_to_eng(question))))
|
@@ -76,7 +74,7 @@ def function4():
|
|
76 |
def function5():
|
77 |
question = flask.request.args.get("question")
|
78 |
if question:
|
79 |
-
return flask.jsonify([{"text":i.get_text(),"score":i.get_score(),"metadata":
|
80 |
else:
|
81 |
return "please provide a question parameter https://shethjenil-apiofbookai.hf.space/fulldetails?question=પ્રભુ છે કે નહિ"
|
82 |
@app.route("/getbookimage/<bookid>/<page>")
|
@@ -84,6 +82,12 @@ def function6(bookid,page):
|
|
84 |
# response = reqget(BeautifulSoup(reqget(f"https://jainqq.org/explore/{bookid}/{page}").content, "html.parser").find("img",class_="img-fluid").get("src"))
|
85 |
# return flask.send_file(BytesIO(response.content), mimetype=response.headers['Content-Type'])
|
86 |
return flask.redirect(BeautifulSoup(reqget(f"https://jainqq.org/explore/{bookid}/{page}").content, "html.parser").find("img",class_="img-fluid").get("src"))
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
if __name__ == '__main__':
|
89 |
-
app.run("0.0.0.0",7860)
|
|
|
3 |
from llama_index.core.base.base_retriever import BaseRetriever
|
4 |
from llama_index.core.schema import TextNode , NodeRelationship
|
5 |
from llama_index.embeddings.huggingface_api import HuggingFaceInferenceAPIEmbedding
|
|
|
6 |
from chromadb import EphemeralClient
|
7 |
from llama_index.vector_stores.chroma import ChromaVectorStore
|
8 |
from requests import get as reqget
|
|
|
10 |
from os import environ
|
11 |
from pickle import load as pickle_load
|
12 |
from bs4 import BeautifulSoup
|
|
|
13 |
import flask
|
14 |
class AIBook:
|
15 |
embed_model:HuggingFaceInferenceAPIEmbedding
|
|
|
47 |
def function():
|
48 |
question = flask.request.args.get("question")
|
49 |
if question is None:
|
50 |
+
return """Please provide a question as 'https://shethjenil-apiofbookai.hf.space?question=પ્રભુ છે કે નહિ'<br>for getting image of question https://shethjenil-apiofbookai.hf.space/question_to_img?question=પ્રભુ છે કે નહિ<br>for get image by book and page https://shethjenil-apiofbookai.hf.space/getbookimage/023657/99<br>for knowing full data with page etc https://shethjenil-apiofbookai.hf.space/fulldetails?question=પ્રભુ છે કે નહિ<br>Change Token as https://shethjenil-apiofbookai.hf.space/changeToken?token=hf_<b>rgPNhjnXpLSodIphwjmRvPbvrovNYnQavj</b><br>Change srcnum as https://shethjenil-apiofbookai.hf.space/changesrcnum?srcnum=2<br><br><form action="/insert_node" method="post" enctype="multipart/form-data"><input type="file" name="file" accept=".book"><input type="submit" value="Upload Book File"></form>"""
|
51 |
if question == "":
|
52 |
return ""
|
53 |
return "\n\n".join(AIBook.nodes_to_guj(book.retrieve(AIBook.translate_to_eng(question))))
|
|
|
74 |
def function5():
|
75 |
question = flask.request.args.get("question")
|
76 |
if question:
|
77 |
+
return flask.jsonify([{"text":i.get_text(),"score":i.get_score(),"metadata":i.node.relationships[NodeRelationship("1")].metadata} for i in book.retrieve(AIBook.translate_to_eng(question))])
|
78 |
else:
|
79 |
return "please provide a question parameter https://shethjenil-apiofbookai.hf.space/fulldetails?question=પ્રભુ છે કે નહિ"
|
80 |
@app.route("/getbookimage/<bookid>/<page>")
|
|
|
82 |
# response = reqget(BeautifulSoup(reqget(f"https://jainqq.org/explore/{bookid}/{page}").content, "html.parser").find("img",class_="img-fluid").get("src"))
|
83 |
# return flask.send_file(BytesIO(response.content), mimetype=response.headers['Content-Type'])
|
84 |
return flask.redirect(BeautifulSoup(reqget(f"https://jainqq.org/explore/{bookid}/{page}").content, "html.parser").find("img",class_="img-fluid").get("src"))
|
85 |
+
@app.route("/question_to_img")
|
86 |
+
def function7():
|
87 |
+
question = flask.request.args.get("question")
|
88 |
+
if question:
|
89 |
+
meta = book.retrieve(AIBook.translate_to_eng(question))[0].node.relationships[NodeRelationship("1")].metadata
|
90 |
+
flask.redirect(BeautifulSoup(reqget(f"https://jainqq.org/explore/{meta['bookid']}/{meta['page']}").content, "html.parser").find("img",class_="img-fluid").get("src"))
|
91 |
|
92 |
if __name__ == '__main__':
|
93 |
+
app.run("0.0.0.0",7860)
|