n8cha commited on
Commit
c9a49fb
·
1 Parent(s): 8f67896

testing with OpenAI

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import gradio as gr
 
 
2
 
3
  css = """
4
  .gradio-container {
@@ -40,8 +42,29 @@ h1 {
40
  """
41
 
42
  def generate_prompt():
43
- prompt = "This is a placeholder prompt. The actual prompt generation will be implemented next."
44
- return prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  with gr.Blocks(
47
  title="Prompt Roulette",
 
1
  import gradio as gr
2
+ import os
3
+ from openai import OpenAI
4
 
5
  css = """
6
  .gradio-container {
 
42
  """
43
 
44
  def generate_prompt():
45
+ try:
46
+ # Read the system prompt from file
47
+ with open("system_prompt.md", "r") as f:
48
+ system_prompt = f.read()
49
+
50
+ # Initialize OpenAI client
51
+ client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
52
+
53
+ # Make API call
54
+ response = client.chat.completions.create(
55
+ model="gpt-3.5-turbo",
56
+ messages=[
57
+ {"role": "system", "content": system_prompt},
58
+ {"role": "user", "content": "Generate a new system prompt."}
59
+ ],
60
+ max_tokens=500,
61
+ temperature=0.9
62
+ )
63
+
64
+ return response.choices[0].message.content
65
+
66
+ except Exception:
67
+ return f"Could not generate a prompt. No fish today."
68
 
69
  with gr.Blocks(
70
  title="Prompt Roulette",