File size: 2,582 Bytes
eae9a22
 
 
afc1cb3
366c565
eae9a22
d7ac493
45e82dd
 
 
 
 
 
 
 
eae9a22
c63b1d2
afc1cb3
d7ac493
366c565
 
 
 
 
 
 
023e765
366c565
 
 
 
 
 
 
 
5bc3d22
 
366c565
 
 
 
5bc3d22
 
 
366c565
5bc3d22
 
 
 
 
 
 
366c565
5bc3d22
366c565
 
5bc3d22
366c565
 
 
45e82dd
 
 
 
 
 
f9b93af
45e82dd
 
 
d7ac493
45e82dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
import openai


def generate_plantuml2(api_key, text):
    openai.api_key = api_key
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "system",
                "content": "You are ChatGPT, a large language model trained by OpenAI. Generate PlantUML code for the following use case or code in natural language.",
            },
            {"role": "user", "content": text},
        ],
    )
    print(response)
    return response["choices"][0]["message"]["content"]

def generate_plantuml(api_key, text):
    openai.api_key = api_key
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {
                "role": "system",
                "content": "You are ChatGPT, a large language model trained by OpenAI. Generate PlantUML code for an architecture that uses Azure services and icons for the following use case or code in natural language. Choose the actors appropriately as per the use case. Do not use '!define SPRITESURL https://raw.githubusercontent.com/rabelenda/cicon-plantuml-sprites/v1.1.0/sprites' as it is outdated.",
            },
            {"role": "user", "content": text},
        ],
    )
    print(response)
    return response["choices"][0]["message"]["content"]

sample_text = '''
!define AzurePuml https://raw.githubusercontent.com/plantuml-stdlib/Azure-PlantUML/master/dist
!includeurl AzurePuml/AzureCommon.puml

actor Customer
actor Restaurant

Customer -> AzureAPIManagement : Login
AzureAPIManagement -> AzureActiveDirectory : Authenticate User
AzureActiveDirectory -> AzureAPIManagement : Return User Info

Customer -> AzureAPIManagement : Place Order
AzureAPIManagement -> AzureFunctionApp : Process Order
AzureFunctionApp -> AzureCosmosDB : Store Order Data
AzureFunctionApp -> Restaurant : Send Order Details
Restaurant -> AzureFunctionApp : Update Order Status
AzureFunctionApp -> AzureCosmosDB : Update Order Data
AzureFunctionApp -> Customer : Send Order Status

AzureFunctionApp -> AzureNotificationHubs : Send Push Notification

legend right
  Online Food Ordering App Architecture
endlegend
'''

iface = gr.Interface(
    fn=generate_plantuml,
    inputs=[
        gr.inputs.Textbox(label="OpenAI API Key"),
        gr.inputs.Textbox(label="Enter use case or code in natural language")
    ],
    outputs=gr.outputs.Textbox(label="Generated PlantUML Code"),
    title="PlantUML Code Generator",
    description="Generate PlantUML code using OpenAI's GPT-3.5-Turbo",
)

iface.launch()