king007's picture
Update app.py
a0a3036
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()