sandeepmhaske commited on
Commit
ff961a6
·
verified ·
1 Parent(s): 17a0057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
- return "Hello "+ name +"!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
1
  import gradio as gr
2
+ import os
3
+ from openai import OpenAI
4
+
5
+ from dotenv import load_dotenv, find_dotenv
6
+ _ = load_dotenv(find_dotenv()) # read local .env file
7
+ os.environ['OPENAI_API_KEY'] = "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"
8
+ client = OpenAI()
9
+
10
+ # account for deprecation of LLM model
11
+ import datetime
12
+ # Get the current date
13
+ current_date = datetime.datetime.now().date()
14
+
15
+ # Define the date after which the model should be set to "gpt-3.5-turbo"
16
+ target_date = datetime.date(2024, 6, 12)
17
+
18
+ # Set the model variable based on the current date
19
+ if current_date > target_date:
20
+ llm_model = "gpt-3.5-turbo"
21
+ else:
22
+ llm_model = "gpt-3.5-turbo-0301"
23
+
24
+ def get_completion(prompt, model=llm_model):
25
+ messages = [{"role": "user", "content": prompt}]
26
+ response = client.chat.completions.create(
27
+ model=model,
28
+ messages=messages,
29
+ temperature=0,
30
+ )
31
+ return response.choices[0].message.content
32
+
33
 
34
  def greet(name):
35
+ return get_completion(name)
36
 
37
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
38
  iface.launch()