Spaces:
Runtime error
Runtime error
Commit
•
45e82dd
1
Parent(s):
d4d426c
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
import openai
|
3 |
-
from plantuml import PlantUML
|
4 |
-
import tempfile
|
5 |
-
import os
|
6 |
|
7 |
-
def
|
8 |
openai.api_key = api_key
|
9 |
response = openai.ChatCompletion.create(
|
10 |
-
model=
|
11 |
-
messages=[
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
)
|
15 |
-
|
16 |
-
return plantuml_code
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
if input_text:
|
25 |
-
plantuml_code = generate_plantuml_code(api_key, input_text)
|
26 |
-
svg_diagram = render_plantuml_diagram(plantuml_code)
|
27 |
-
return plantuml_code, svg_diagram
|
28 |
-
|
29 |
-
inputs = [
|
30 |
-
gr.inputs.Textbox(label="Enter OpenAI API Key"),
|
31 |
-
gr.inputs.Textbox(lines=5, label="Enter use case in natural language (optional)"),
|
32 |
-
gr.inputs.Textbox(lines=5, label="Paste PlantUML code (optional)")
|
33 |
-
]
|
34 |
-
outputs = [
|
35 |
-
gr.outputs.Textbox(label="Generated PlantUML Code"),
|
36 |
-
gr.outputs.HTML(label="Rendered Diagram")
|
37 |
-
]
|
38 |
-
|
39 |
-
gr.Interface(fn=app, inputs=inputs, outputs=outputs).launch()
|
|
|
1 |
import gradio as gr
|
2 |
import openai
|
|
|
|
|
|
|
3 |
|
4 |
+
def generate_plantuml(api_key, text):
|
5 |
openai.api_key = api_key
|
6 |
response = openai.ChatCompletion.create(
|
7 |
+
model="gpt-3.5-turbo",
|
8 |
+
messages=[
|
9 |
+
{
|
10 |
+
"role": "system",
|
11 |
+
"content": "You are ChatGPT, a large language model trained by OpenAI. Generate PlantUML code for the following use case or code in natural language.",
|
12 |
+
},
|
13 |
+
{"role": "user", "content": text},
|
14 |
+
],
|
15 |
)
|
16 |
+
return response["messages"][-1]["content"]
|
|
|
17 |
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=generate_plantuml,
|
20 |
+
inputs=[
|
21 |
+
gr.inputs.Textbox(label="OpenAI API Key"),
|
22 |
+
gr.inputs.Textbox(label="Enter use case or code in natural language")
|
23 |
+
],
|
24 |
+
outputs=gr.outputs.Code(label="Generated PlantUML Code"),
|
25 |
+
title="PlantUML Code Generator",
|
26 |
+
description="Generate PlantUML code using OpenAI's GPT-3.5-Turbo",
|
27 |
+
)
|
28 |
|
29 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|