Omar Solano commited on
Commit
8c851ec
1 Parent(s): 9d1039f
Files changed (2) hide show
  1. gradio_anthropic.py +1 -2
  2. gradio_openai.py +8 -10
gradio_anthropic.py CHANGED
@@ -1,8 +1,7 @@
1
  import os
 
2
 
3
  import gradio as gr
4
- from openai import OpenAI
5
- import logging
6
  import anthropic
7
  from dotenv import load_dotenv
8
 
 
1
  import os
2
+ import logging
3
 
4
  import gradio as gr
 
 
5
  import anthropic
6
  from dotenv import load_dotenv
7
 
gradio_openai.py CHANGED
@@ -1,9 +1,11 @@
1
  import os
 
2
 
3
  import gradio as gr
4
  from openai import OpenAI
5
- import logging
6
- import anthropic
 
7
 
8
  logging.basicConfig(level=logging.INFO)
9
  logging.getLogger("gradio").setLevel(logging.INFO)
@@ -18,23 +20,19 @@ def generate_completion(input, history):
18
  messages = [
19
  {
20
  "role": "system",
21
- "content": "You are a world-class extractor of information from messy job postings.",
22
  }
23
  ]
24
 
25
- # Convert history from a list of lists to a list of dictionaries
26
  if history:
27
  for entry in history:
28
- # Assuming each entry has exactly 2 elements: user input and assistant response
29
- if len(entry) == 2: # Validate format
30
- # Append user message
31
  messages.append(
32
  {
33
  "role": "user",
34
  "content": entry[0],
35
  }
36
  )
37
- # Append assistant response
38
  messages.append(
39
  {
40
  "role": "assistant",
@@ -42,7 +40,6 @@ def generate_completion(input, history):
42
  }
43
  )
44
 
45
- # Append the current user message
46
  messages.append(
47
  {
48
  "role": "user",
@@ -67,7 +64,8 @@ def generate_completion(input, history):
67
  yield answer_str
68
 
69
 
 
 
70
  if __name__ == "__main__":
71
- demo = gr.ChatInterface(fn=generate_completion)
72
  demo.queue()
73
  demo.launch()
 
1
  import os
2
+ import logging
3
 
4
  import gradio as gr
5
  from openai import OpenAI
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv(".env")
9
 
10
  logging.basicConfig(level=logging.INFO)
11
  logging.getLogger("gradio").setLevel(logging.INFO)
 
20
  messages = [
21
  {
22
  "role": "system",
23
+ "content": "You are a world-class assistant.",
24
  }
25
  ]
26
 
 
27
  if history:
28
  for entry in history:
29
+ if len(entry) == 2:
 
 
30
  messages.append(
31
  {
32
  "role": "user",
33
  "content": entry[0],
34
  }
35
  )
 
36
  messages.append(
37
  {
38
  "role": "assistant",
 
40
  }
41
  )
42
 
 
43
  messages.append(
44
  {
45
  "role": "user",
 
64
  yield answer_str
65
 
66
 
67
+ demo = gr.ChatInterface(fn=generate_completion)
68
+
69
  if __name__ == "__main__":
 
70
  demo.queue()
71
  demo.launch()