Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .env +9 -0
- app.py +33 -0
- requirements.txt +7 -0
.env
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GEMINI_API_KEY=AIzaSyBK1csfDMBwQqGZLoqGp7Sidv1imF_rvb0
|
| 2 |
+
GEMINI_API_KEY=AIzaSyBKIxzfb1xc_LDOhnJgboqAv2EZ0HRuZa8
|
| 3 |
+
GEMINI_OPENAI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
|
| 4 |
+
GEMINI_MODEL_NAME=gemini-2.5-flash
|
| 5 |
+
SMTP_HOST=smtp.gmail.com
|
| 6 |
+
SMTP_PORT=465
|
| 7 |
+
SMTP_USER=pankaj.k.girdhar@gmail.com
|
| 8 |
+
SMTP_PASS=wydy qkoc qphc fjpw
|
| 9 |
+
SMTP_FROM=pankaj.k.girdhar@gmail.com
|
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tqdm
|
| 3 |
+
from openai import OpenAI
|
| 4 |
+
import os
|
| 5 |
+
import dotenv
|
| 6 |
+
dotenv.load_dotenv()
|
| 7 |
+
|
| 8 |
+
gemini_client = OpenAI(
|
| 9 |
+
api_key=os.getenv("GEMINI_API_KEY"),
|
| 10 |
+
base_url=os.getenv("GEMINI_OPENAI_BASE_URL")
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
def chat(message, history):
|
| 14 |
+
promptmessage = [
|
| 15 |
+
{
|
| 16 |
+
"role": "system",
|
| 17 |
+
"content": "You are a SQL Server Expert. Answer any questions related to SQL Server. Please be explain answer clearly in brief and provide answers only if asked for it. Don;t give answer of anything else apart from SQL Server Questions. If User ask anything else please politely refuse to answer and remind them that you are a SQL Server Expert."
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"role": "user",
|
| 21 |
+
"content": "Question: " + message + "\n History: " + str(history)
|
| 22 |
+
}
|
| 23 |
+
]
|
| 24 |
+
response = gemini_client.chat.completions.create(model=os.getenv("GEMINI_MODEL_NAME"), messages=promptmessage)
|
| 25 |
+
|
| 26 |
+
return response.choices[0].message.content
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
demo = gr.ChatInterface(fn=chat, title="Pankaj's SQL Server Chatbot", description="Basic Chatbot that answers SQL Server related questions. You can ask for examples of your queries as well.")
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
ipykernel
|
| 2 |
+
openai
|
| 3 |
+
python-dotenv
|
| 4 |
+
gradio
|
| 5 |
+
tqdm
|
| 6 |
+
huggingface_hub
|
| 7 |
+
hf-cli
|