Kathirsci commited on
Commit
91f145c
1 Parent(s): da0dc94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -44
app.py CHANGED
@@ -1,48 +1,14 @@
1
- import gradio as gr
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
- # Load model and embeddings
12
- embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2", device="cpu")
13
- llm = HuggingFaceLLM(model_name="meta-llama/Meta-Llama-3.1-8B-Instruct")
14
 
15
- def process_pdf_and_summarize(file):
16
- try:
17
- # Load PDF document
18
- loader = PyPDFLoader(file.name)
19
- documents = loader.load()
20
 
21
- # Summarize the document
22
- map_template = """Summarize the following text:\n\n{text}\n\nSummary:"""
23
- map_prompt = PromptTemplate.from_template(map_template)
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
- chain = MapReduceChain.from_chain_type(
28
- llm=llm,
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)