ahmadmac commited on
Commit
211fb31
·
verified ·
1 Parent(s): 1a51e31

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain import LLMChain
3
+ from langchain.prompts import ChatPromptTemplate,PromptTemplate
4
+ from langchain.schema import (
5
+ HumanMessage,
6
+ SystemMessage
7
+ )
8
+ import os
9
+ from langchain_google_genai import GoogleGenerativeAI
10
+ google_api_key=os.environ["google_api_key"]
11
+
12
+
13
+ llm = GoogleGenerativeAI(model='gemini-1.5-pro', google_api_key=google_api_key)
14
+
15
+ messages = [
16
+ SystemMessage(content="You are an expert at extracting entities from text."),
17
+ HumanMessagePromptTemplate.from_template("{text}")
18
+ ]
19
+
20
+ chat_prompt = ChatPromptTemplate.from_messages(messages)
21
+ chain = LLMChain(llm=llm, prompt=chat_prompt)
22
+
23
+ def extract_entities(text):
24
+ result = chain.run(text)
25
+ return result
26
+
27
+ def chatbot(text, history):
28
+ response = extract_entities(text)
29
+ return response
30
+
31
+ iface = gr.ChatInterface(
32
+ fn=chatbot,
33
+ title="Entity Extraction Chatbot",
34
+ description="Extract entities from text using Gemini 1.5 Pro."
35
+ )
36
+
37
+ iface.launch()