Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from langchain import LLMChain | |
| from langchain.prompts import ChatPromptTemplate,PromptTemplate | |
| from langchain.schema import ( | |
| HumanMessage, | |
| SystemMessage | |
| ) | |
| import os | |
| from langchain_google_genai import GoogleGenerativeAI | |
| google_api_key=os.environ["google_api_key"] | |
| llm = GoogleGenerativeAI(model='gemini-1.5-pro', google_api_key=google_api_key) | |
| messages = [ | |
| SystemMessage(content="You are an expert at extracting entities from text."), | |
| HumanMessagePromptTemplate.from_template("{text}") | |
| ] | |
| chat_prompt = ChatPromptTemplate.from_messages(messages) | |
| chain = LLMChain(llm=llm, prompt=chat_prompt) | |
| def extract_entities(text): | |
| result = chain.run(text) | |
| return result | |
| def chatbot(text, history): | |
| response = extract_entities(text) | |
| return response | |
| iface = gr.ChatInterface( | |
| fn=chatbot, | |
| title="Entity Extraction Chatbot", | |
| description="Extract entities from text using Gemini 1.5 Pro." | |
| ) | |
| iface.launch() | |