prompt-query / app.py
king007's picture
Update app.py
436eb4a
import gradio as gr
import os
import openai
import requests
import json
import pandas as pd
import difflib
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 search
def getPromptByPromptType(promptType):
# if(True):
# promptType="blog"
# match = difflib.get_close_matches(promptType, ["blog1","blog2"])
# print(match)
# return match
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)
listA = []
matchList=[]
matchStr=""
for item in table_json:
print(item['prompt'])
isMatchFlag=False
if promptType in item['prompt']:
isMatchFlag=True
if promptType.lower() in item['prompt']:
isMatchFlag=True
if promptType.upper() in item['prompt']:
isMatchFlag=True
if isMatchFlag:
match = item['prompt']
matchStr=matchStr+match+"||||"
return matchStr
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()