artificialguybr commited on
Commit
4f2de6f
·
1 Parent(s): a4b8ea3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -8,6 +8,10 @@ import io
8
  def generate_knowledge_graph(api_key, user_input):
9
  openai.api_key = api_key
10
 
 
 
 
 
11
  # Chamar a API da OpenAI
12
  print("Chamando a API da OpenAI...")
13
  completion = openai.ChatCompletion.create(
@@ -122,15 +126,31 @@ def generate_knowledge_graph(api_key, user_input):
122
 
123
  return image
124
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  iface = gr.Interface(
126
  fn=generate_knowledge_graph,
127
  inputs=[
128
  gr.inputs.Textbox(label="OpenAI API Key", type="password"),
129
- gr.inputs.Textbox(label="User Input for Graph"),
130
  ],
131
  outputs=gr.outputs.Image(type="pil", label="Generated Knowledge Graph"),
132
  live=False,
 
133
  )
134
 
 
 
 
135
  print("Iniciando a interface Gradio...")
136
- iface.launch()
 
8
  def generate_knowledge_graph(api_key, user_input):
9
  openai.api_key = api_key
10
 
11
+ # Ensure both API key and user input are provided
12
+ if not api_key or not user_input:
13
+ raise ValueError("Please provide both the OpenAI API Key and User Input")
14
+
15
  # Chamar a API da OpenAI
16
  print("Chamando a API da OpenAI...")
17
  completion = openai.ChatCompletion.create(
 
126
 
127
  return image
128
 
129
+ # Define a title and description for the Gradio interface using Markdown
130
+ title_and_description = """
131
+ # Instagraph - Knowledge Graph Generator
132
+
133
+ **Created by [ArtificialGuyBR](https://twitter.com/ArtificialGuyBR)**
134
+
135
+ This interactive knowledge graph generator is inspired by [this GitHub project](https://github.com/yoheinakajima/instagraph/).
136
+
137
+ Enter your OpenAI API Key and a question, and let the AI create a detailed knowledge graph for you.
138
+ """
139
+
140
+ # Create the Gradio interface with queueing enabled and concurrency_count set to 10
141
  iface = gr.Interface(
142
  fn=generate_knowledge_graph,
143
  inputs=[
144
  gr.inputs.Textbox(label="OpenAI API Key", type="password"),
145
+ gr.inputs.Textbox(label="User Input for Graph", type="text"),
146
  ],
147
  outputs=gr.outputs.Image(type="pil", label="Generated Knowledge Graph"),
148
  live=False,
149
+ title=title_and_description,
150
  )
151
 
152
+ # Enable queueing system for multiple users
153
+ iface.queue(concurrency_count=10)
154
+
155
  print("Iniciando a interface Gradio...")
156
+ iface.launch()