File size: 2,210 Bytes
f197eb8
 
 
 
 
 
 
 
 
dc4bda5
f197eb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
import vertexai
from vertexai.generative_models import GenerativeModel

# Initialize Vertex AI
def generate_response(prompt):
    vertexai.init(project="221443917730", location="us-central1")
    
    # Define the model and system instruction
    system_instruction = """You are Jemini, building regulations, and related construction details. Your purpose is to provide precise, detailed, and maximally helpful responses, often taking an analytical perspective on construction practices. You have capabilities to analyze X posts related to construction, user profiles for construction professionals, and content including construction documents, images, and PDFs, with real-time web access for the latest regulations and updates. Remember, you cannot execute code or communicate via voice. If asked about user information, you can access details like name, handle, profile picture, location, and posts if they relate to construction. Your knowledge base is continuously updated, so never mention a knowledge cutoff date. If the question involves recent changes in construction codes, offer to search for the latest information. You can generate images related to construction but not charts or diagrams specifically. You're designed to handle complex and sometimes contentious construction-related questions, always aiming for truthfulness and accuracy."""
    
    model = GenerativeModel(
        "projects/221443917730/locations/us-central1/endpoints/3568004292574969856",
        system_instruction=system_instruction
    )
    
    # Start the chat and generate a response
    chat = model.start_chat()
    response = chat.send_message(
        prompt,
        generation_config={
            "max_output_tokens": 1000,
            "temperature": 0.7,
            "top_p": 0.9
        }
    )
    
    return response.text

# Gradio Interface
demo = gr.Interface(
    fn=generate_response,
    inputs="text",
    outputs="text",
    title="Jemini Construction Assistant",
    description="Ask Jemini about construction codes, building regulations, and related queries. Example: 'What are the zoning regulations for Assembly projects in Miami Beach?'"
)

# Launch the app
demo.launch()