Vijay Agrawal commited on
Commit
3f86df8
·
1 Parent(s): b506044
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +42 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -3,8 +3,8 @@ title: Simpleaichatbot
3
  emoji: 🦀
4
  colorFrom: gray
5
  colorTo: green
6
- sdk: gradio
7
- sdk_version: 6.0.2
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
3
  emoji: 🦀
4
  colorFrom: gray
5
  colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.40.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import os to handle environment variables
2
+ #
3
+ # To run this app
4
+ #
5
+ # streamlit run <path to this file, for example, rag\streamlit_app_basic.py>
6
+ #
7
+ import os
8
+ from dotenv import load_dotenv
9
+ import streamlit as st
10
+ from openai import AzureOpenAI
11
+
12
+ load_dotenv()
13
+
14
+ st.subheader("AI chatbot using Azure OpenAI")
15
+
16
+ def generate_response(input_text):
17
+ client = AzureOpenAI(
18
+ azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
19
+ api_key=os.getenv("AZURE_OPENAI_API_KEY"),
20
+ api_version=os.getenv("AZURE_OPENAI_API_VERSION")
21
+ )
22
+ model_name=os.getenv("AZURE_OPENAI_MODEL_NAME")
23
+
24
+ try:
25
+ response = client.chat.completions.create(
26
+ model=model_name,
27
+ messages=[
28
+ {"role": "system", "content":
29
+ """ You are a helpful AI assistant. Answer as concisely as possible.
30
+ """
31
+ },
32
+ {"role": "user", "content": input_text}
33
+ ] )
34
+ #print (response)
35
+ answer = response.choices[0].message.content.strip()
36
+ except Exception as e:
37
+ print(e) # Log error and continue
38
+ st.info(answer) # Display the response content
39
+
40
+ user_question = st.text_input("Ask any question. Press enter to submit", key="user_question")
41
+ if user_question:
42
+ generate_response(user_question)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ python-dotenv
2
+ openai
3
+ streamlit