ahmadmac commited on
Commit
6ba7abd
·
verified ·
1 Parent(s): f96d782

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -14
app.py CHANGED
@@ -1,16 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import os
3
 
4
  from langchain_google_genai import GoogleGenerativeAI
5
  from langchain import LLMChain
6
- from langchain.prompts import ChatPromptTemplate,PromptTemplate,HumanMessagePromptTemplate
7
- from langchain.schema import (
8
- HumanMessage,
9
- SystemMessage
10
- )
11
-
12
- google_api_key=os.environ["google_api_key"]
13
 
 
14
 
15
  llm = GoogleGenerativeAI(model='gemini-1.5-pro', google_api_key=google_api_key)
16
 
@@ -20,20 +55,21 @@ messages = [
20
  ]
21
 
22
  chat_prompt = ChatPromptTemplate.from_messages(messages)
 
23
  chain = LLMChain(llm=llm, prompt=chat_prompt)
24
 
25
  def extract_entities(text):
26
  result = chain.run(text)
27
  return result
28
 
29
- def chatbot(text, history):
30
- response = extract_entities(text)
31
- return response
32
-
33
- iface = gr.ChatInterface(
34
- fn=chatbot,
35
- title="Entity Extraction Chatbot",
36
  description="Extract entities from text using Gemini 1.5 Pro."
37
  )
38
 
 
39
  iface.launch()
 
 
1
+ # import gradio as gr
2
+ # import os
3
+
4
+ # from langchain_google_genai import GoogleGenerativeAI
5
+ # from langchain import LLMChain
6
+ # from langchain.prompts import ChatPromptTemplate,PromptTemplate,HumanMessagePromptTemplate
7
+ # from langchain.schema import (
8
+ # HumanMessage,
9
+ # SystemMessage
10
+ # )
11
+
12
+ # google_api_key=os.environ["google_api_key"]
13
+
14
+
15
+ # llm = GoogleGenerativeAI(model='gemini-1.5-pro', google_api_key=google_api_key)
16
+
17
+ # messages = [
18
+ # SystemMessage(content="You are an expert at extracting entities from text."),
19
+ # HumanMessagePromptTemplate.from_template("{text}")
20
+ # ]
21
+
22
+ # chat_prompt = ChatPromptTemplate.from_messages(messages)
23
+ # chain = LLMChain(llm=llm, prompt=chat_prompt)
24
+
25
+ # def extract_entities(text):
26
+ # result = chain.run(text)
27
+ # return result
28
+
29
+ # def chatbot(text, history):
30
+ # response = extract_entities(text)
31
+ # return response
32
+
33
+ # iface = gr.ChatInterface(
34
+ # fn=chatbot,
35
+ # title="Entity Extraction Chatbot",
36
+ # description="Extract entities from text using Gemini 1.5 Pro."
37
+ # )
38
+
39
+ # iface.launch()
40
  import gradio as gr
41
  import os
42
 
43
  from langchain_google_genai import GoogleGenerativeAI
44
  from langchain import LLMChain
45
+ from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
46
+ from langchain.schema import SystemMessage
 
 
 
 
 
47
 
48
+ google_api_key = os.getenv("google_api_key")
49
 
50
  llm = GoogleGenerativeAI(model='gemini-1.5-pro', google_api_key=google_api_key)
51
 
 
55
  ]
56
 
57
  chat_prompt = ChatPromptTemplate.from_messages(messages)
58
+
59
  chain = LLMChain(llm=llm, prompt=chat_prompt)
60
 
61
  def extract_entities(text):
62
  result = chain.run(text)
63
  return result
64
 
65
+ iface = gr.Interface(
66
+ fn=extract_entities,
67
+ inputs=gr.Textbox(label="Enter your text"),
68
+ outputs=gr.Textbox(label="Extracted Entities"),
69
+ title="Entity Extraction Tool",
 
 
70
  description="Extract entities from text using Gemini 1.5 Pro."
71
  )
72
 
73
+
74
  iface.launch()
75
+