Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from langchain_community.document_loaders import PyPDFLoader
|
| 5 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 6 |
+
from langchain_community.vectorstores import Chroma
|
| 7 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 8 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 9 |
+
from langchain_community.llms import HuggingFacePipeline
|
| 10 |
+
from langchain.chains import ConversationChain
|
| 11 |
+
from langchain.memory import ConversationBufferMemory
|
| 12 |
+
from langchain_community.llms import HuggingFaceEndpoint
|
| 13 |
+
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
import chromadb
|
| 16 |
+
from unidecode import unidecode
|
| 17 |
+
|
| 18 |
+
from transformers import AutoTokenizer
|
| 19 |
+
import transformers
|
| 20 |
+
import torch
|
| 21 |
+
import tqdm
|
| 22 |
+
import accelerate
|
| 23 |
+
import re
|
| 24 |
+
|
| 25 |
+
list_llm = ["HuggingFaceH4/zephyr-7b-beta", "mistralai/Mistral-7B-Instruct-v0.2"]
|
| 26 |
+
list_llm_simple = [os.path.basename(llm) for llm in list_llm]
|
| 27 |
+
|
| 28 |
+
def summarize_document(document_text):
|
| 29 |
+
# Your summarization code here
|
| 30 |
+
summary = "The document covers various topics such as X, Y, and Z, providing detailed insights into each aspect."
|
| 31 |
+
return summary
|
| 32 |
+
|
| 33 |
+
def demo():
|
| 34 |
+
with gr.Blocks(theme="base") as demo:
|
| 35 |
+
gr.Markdown("<center><h2>PDF Summarizer</center></h2>")
|
| 36 |
+
|
| 37 |
+
text_input = gr.Textbox(placeholder="Paste your document text here", label="Document Text")
|
| 38 |
+
summarize_btn = gr.Button("Summarize")
|
| 39 |
+
summary_output = gr.Textbox(readonly=True, label="Summary")
|
| 40 |
+
|
| 41 |
+
summarize_btn.click(summarize_document, inputs=[text_input], outputs=[summary_output])
|
| 42 |
+
|
| 43 |
+
demo.launch()
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo()
|