File size: 2,039 Bytes
17f7e3c
 
 
 
 
3b4eeb1
17f7e3c
 
3475d99
 
17f7e3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0a3036
2c77548
4eb0cab
2c77548
7c27d23
 
e98d4fe
7c27d23
 
2c77548
e98d4fe
21e762f
 
2c77548
 
 
e98d4fe
2c77548
3b4eeb1
17f7e3c
 
2c77548
 
3cc8925
1cef11f
2c77548
 
1cef11f
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
import gradio as gr
import os
import openai
import requests
import json
import pandas as pd


prompt_templates = {}
question_templates = {}

def download_prompt_templates2():
    url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"
    response = requests.get(url)

    for line in response.text.splitlines()[1:]:
        act, prompt = line.split('","')
        prompt_templates[act.replace('"', '')] = prompt.replace('"', '')

    choices = list(prompt_templates.keys())
    return choices


def download_question_templates2():
    url = "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"
    response = requests.get(url)

    for line in response.text.splitlines()[1:]:
        act, prompt = line.split('","')
        question_templates[act.replace('"', '')] = prompt.replace('"', '')

    choices = list(question_templates.keys())
    return choices
    
def getQuestionAndPrompt():
    choice1=download_question_templates2()
    choice2=download_prompt_templates2()
    return choice1,choice2

#use for select box list
def getPromptByPromptType(promptType):
    print(promptType)
    if(promptType==""):
        table_df = pd.read_csv("prompts.csv", header=0,usecols=["act"])
        table_json=table_df.to_json(orient="records")
            
        return table_json

    else:
        table_df = pd.read_csv("prompts.csv", header=0,usecols=["act","prompt"])
        table_jsonStr=table_df.to_json(orient="records")
        table_json=json.loads(table_jsonStr)
        for item in table_json:
            if(item['act']==promptType):
                return item['prompt']
        return ""
    

question_textbox = gr.Textbox(label="", lines=10)
prompt_textbox = gr.Textbox(label="", lines=10)

promptType_textbox = gr.Textbox(label="", lines=2)
json_output=gr.JSON(label="Output", visible=True)
jsonstr_output = gr.Textbox(label="", lines=10)
gr.Interface(fn=getPromptByPromptType,
             inputs=[promptType_textbox],
             outputs=[jsonstr_output]).launch()