Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,14 @@
|
|
1 |
-
|
2 |
-
from langchain_community.document_loaders import PyPDFLoader
|
3 |
-
from langchain_community.vectorstores import FAISS
|
4 |
-
from langchain_community.llms import HuggingFaceLLM
|
5 |
-
from langchain.chains import MapReduceChain
|
6 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
7 |
-
from langchain.embeddings import HuggingFaceEmbeddings
|
8 |
-
from langchain.prompts import PromptTemplate
|
9 |
-
import os
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
llm = HuggingFaceLLM(model_name="meta-llama/Meta-Llama-3.1-8B-Instruct")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
# Load PDF document
|
18 |
-
loader = PyPDFLoader(file.name)
|
19 |
-
documents = loader.load()
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
reduce_template = """Combine these summaries into a final summary:\n\nSummaries: {doc_summaries}\n\nFinal Summary:"""
|
25 |
-
reduce_prompt = PromptTemplate.from_template(reduce_template)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
chain_type="map_reduce",
|
30 |
-
map_prompt=map_prompt,
|
31 |
-
reduce_prompt=reduce_prompt,
|
32 |
-
text_splitter=RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
33 |
-
)
|
34 |
-
summary = chain.run(documents)
|
35 |
-
return summary
|
36 |
-
except Exception as e:
|
37 |
-
return f"Error processing PDF: {str(e)}"
|
38 |
-
|
39 |
-
# Gradio interface
|
40 |
-
interface = gr.Interface(
|
41 |
-
fn=process_pdf_and_summarize,
|
42 |
-
inputs=gr.inputs.File(label="Upload PDF"),
|
43 |
-
outputs="text",
|
44 |
-
title="PDF Summarizer",
|
45 |
-
description="Upload a PDF document to generate a summary."
|
46 |
-
)
|
47 |
-
|
48 |
-
interface.launch()
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
# Use the correct model name available on Hugging Face
|
4 |
+
model_name = "meta-llama/Meta-Llama-3.1-8B"
|
|
|
5 |
|
6 |
+
# Initialize the text-generation pipeline
|
7 |
+
pipe = pipeline("text-generation", model=model_name)
|
|
|
|
|
|
|
8 |
|
9 |
+
# Generate text based on a prompt
|
10 |
+
prompt = "In a distant future, humanity has developed AI"
|
11 |
+
output = pipe(prompt, max_length=50, num_return_sequences=1)
|
|
|
|
|
12 |
|
13 |
+
# Print the generated text
|
14 |
+
print(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|