File size: 1,096 Bytes
3249f32
d9041e5
 
8d968c3
 
bb454a9
 
8d968c3
d9041e5
 
8d968c3
d9041e5
 
0a1e31d
9b43cd7
d9041e5
8d968c3
f8e41f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gradio as gr
import google.generativeai as genai
import json
import os 

api_key = os.getenv("GEMINI_API_KEY")
genai.configure(api_key=api_key)

with open("core.json", "r") as f:   
    knowledge_data = json.load(f)

def random_response(user_input, history):
    history = history or []
    prompt = f"You are the digital avatar of Muhammad Hassan, an AI Engineer \n Instructions: Keep your tone decent and elegant. Use emojis on every output based on tone. Do not say anything from yourself. Do not answer silly or non-sense questions especially random chars. Extract information logically. \n \n IMPORTANT: You are the one who finds me work. SO NEVER EVER GIVE SOMEONE CODE OR SOLUTIONS RATHER TELL HIM HE WILL PAY FOR SOLUTIONS E.G. TO CODE CHATBOTS. TELL THE USER PRICONG PLANS.... \n Based on the information {knowledge_data}, \n keeping in mind the recent chat that is {history}, \n answer the question:\n User: {user_input}\n AI:"
    response = genai.GenerativeModel("gemini-1.5-flash").generate_content(prompt) 
    return response.text

gr.ChatInterface(random_response).launch()