Rahatara commited on
Commit
c11b454
1 Parent(s): 9105d7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Any, Tuple
2
  import gradio as gr
3
  from langchain_openai import OpenAIEmbeddings
4
  from langchain_community.vectorstores import Chroma
@@ -13,7 +13,7 @@ import openai
13
 
14
  openai.api_key = "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"
15
 
16
- def add_text(history, text: str):
17
  if not text:
18
  raise gr.Error("Enter text")
19
  history.append((text, ""))
@@ -32,7 +32,7 @@ class MyApp:
32
  self.chain = self.build_chain(file)
33
  return self.chain
34
 
35
- def process_file(self, file: str) -> Image:
36
  loader = PyMuPDFLoader(file.name)
37
  self.documents = loader.load()
38
  pattern = r"/([^/]+)$"
@@ -47,7 +47,7 @@ class MyApp:
47
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
48
  return image
49
 
50
- def build_chain(self, file: str) -> str:
51
  embeddings = OpenAIEmbeddings(openai_api_key=self.OPENAI_API_KEY)
52
  pdfsearch = Chroma.from_documents(
53
  self.documents,
@@ -78,14 +78,14 @@ def get_response(history, query, file):
78
  history[-1][-1] += char
79
  yield history, "", source_texts_str
80
 
81
- def render_file(file) -> Image:
82
  doc = fitz.open(file.name)
83
  page = doc[0]
84
  pix = page.get_pixmap(dpi=150)
85
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
86
  return image
87
 
88
- def purge_chat_and_render_first(file) -> Tuple[Image, list]:
89
  app.chat_history = []
90
  doc = fitz.open(file.name)
91
  page = doc[0]
 
1
+ from typing import Any, List, Tuple
2
  import gradio as gr
3
  from langchain_openai import OpenAIEmbeddings
4
  from langchain_community.vectorstores import Chroma
 
13
 
14
  openai.api_key = "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"
15
 
16
+ def add_text(history: List[Tuple[str, str]], text: str) -> List[Tuple[str, str]]:
17
  if not text:
18
  raise gr.Error("Enter text")
19
  history.append((text, ""))
 
32
  self.chain = self.build_chain(file)
33
  return self.chain
34
 
35
+ def process_file(self, file) -> Image.Image:
36
  loader = PyMuPDFLoader(file.name)
37
  self.documents = loader.load()
38
  pattern = r"/([^/]+)$"
 
47
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
48
  return image
49
 
50
+ def build_chain(self, file) -> str:
51
  embeddings = OpenAIEmbeddings(openai_api_key=self.OPENAI_API_KEY)
52
  pdfsearch = Chroma.from_documents(
53
  self.documents,
 
78
  history[-1][-1] += char
79
  yield history, "", source_texts_str
80
 
81
+ def render_file(file) -> Image.Image:
82
  doc = fitz.open(file.name)
83
  page = doc[0]
84
  pix = page.get_pixmap(dpi=150)
85
  image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
86
  return image
87
 
88
+ def purge_chat_and_render_first(file) -> Tuple[Image.Image, list]:
89
  app.chat_history = []
90
  doc = fitz.open(file.name)
91
  page = doc[0]