storresbusquets commited on
Commit
cb67dcf
1 Parent(s): c6f6713

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def greet(text):
4
+
5
+ from langchain.chat_models import ChatOllama
6
+ from langchain.document_loaders import WebBaseLoader
7
+ from langchain.chains.summarize import load_summarize_chain
8
+
9
+ loader = WebBaseLoader("https://lilianweng.github.io/posts/2023-06-23-agent/")
10
+ docs = loader.load()
11
+
12
+ llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k")
13
+ chain = load_summarize_chain(llm, chain_type="stuff")
14
+
15
+ chain.run(docs)
16
+
17
+ from langchain.chains.llm import LLMChain
18
+ from langchain.prompts import PromptTemplate
19
+ from langchain.chains.combine_documents.stuff import StuffDocumentsChain
20
+
21
+ # Define prompt
22
+ prompt_template = """Write a concise summary of the following:
23
+ "{text}"
24
+ CONCISE SUMMARY:"""
25
+ prompt = PromptTemplate.from_template(prompt_template)
26
+
27
+ # Define LLM chain
28
+ llm = ChatOllama(temperature=0, model_name="falcon:7b-instruct")
29
+ llm_chain = LLMChain(llm=llm, prompt=prompt)
30
+
31
+ # Define StuffDocumentsChain
32
+ stuff_chain = StuffDocumentsChain(
33
+ llm_chain=llm_chain, document_variable_name="text"
34
+ )
35
+
36
+ docs = loader.load()
37
+ summary = stuff_chain.run(docs)
38
+
39
+ return summary
40
+
41
+ with gr.Blocks() as demo:
42
+ text = gr.Textbox(label="Text")
43
+ summary = gr.Textbox(label="Summary")
44
+ greet_btn = gr.Button("Submit")
45
+ greet_btn.click(fn=greet, inputs=text, outputs=summary, api_name="greet")
46
+
47
+ demo.launch()