hra commited on
Commit
8b06302
·
1 Parent(s): d85cb88

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ import gradio as gr
4
+ import random
5
+ import time
6
+ import os
7
+ import datetime
8
+ from datetime import datetime
9
+
10
+ print('for update')
11
+
12
+ HRA_TOKEN=os.getenv("HRA_TOKEN")
13
+
14
+ from langchain.agents import load_tools, Tool, initialize_agent
15
+ from langchain.llms import OpenAI
16
+ from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
17
+ from langchain.agents import initialize_agent, Tool
18
+ from langchain import LLMChain
19
+ from langchain import PromptTemplate
20
+
21
+
22
+
23
+ headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
24
+ url_decodemprompts='https://us-central1-createinsightsproject.cloudfunctions.net/gethrahfprompts'
25
+
26
+ data={"prompt_type":'chatgpt_blog',"hra_token":HRA_TOKEN}
27
+ try:
28
+ r = requests.post(url_decodemprompts, data=json.dumps(data), headers=headers)
29
+ except requests.exceptions.ReadTimeout as e:
30
+ print(e)
31
+ #print(r.content)
32
+
33
+ prompt=str(r.content, 'UTF-8')
34
+ print(prompt)
35
+ template=prompt.split('SEPERATOR')[0]
36
+ querieslist=prompt.split('SEPERATOR')[1].split(',')
37
+
38
+
39
+
40
+ def blog(text_inp1,text_inp2):
41
+ print(text_inp1,text_inp2)
42
+ print(datetime.today().strftime("%d-%m-%Y"))
43
+ if text_inp2!='':
44
+ OPEN_API_TOKEN = text_inp2
45
+
46
+ llm = OpenAI(temperature=0)
47
+
48
+ prompt_template = PromptTemplate(
49
+ input_variables=["query"],
50
+ template=template
51
+ )
52
+
53
+ bloglist=[]
54
+ for each in querieslist:
55
+ query = each
56
+
57
+
58
+ llm_chain = LLMChain(prompt=prompt_template, llm=llm,verbose=True)
59
+ result=llm_chain.run(query)
60
+ #print(result)
61
+ bloglist.append(result)
62
+
63
+ blog="Title:"+bloglist[len(bloglist)-1]+"\n\n"
64
+ for i in range(len(bloglist)-1):
65
+ temp=querieslist[i]+'\n'+bloglist[i]+'\n\n'
66
+ blog+=temp
67
+ print(blog)
68
+ return(blog)
69
+ else:
70
+ return "Enter OpenAPI key"
71
+
72
+ with gr.Blocks() as demo:
73
+ with gr.Row():
74
+ gr.Markdown("<h1><center>Everybody Can Blog</center></h1>")
75
+ gr.Markdown(
76
+ """Everybody can blog. Just enter a topic/ keyword & get a full blog from ChatGPT model. See examples for guidance. Experience the power of Prompt Engineering."""
77
+ )
78
+ with gr.Row():
79
+ with gr.Column():
80
+ textbox1 = gr.Textbox(placeholder="Enter topic/ keyword to generate blog...", lines=1,label='Topic')
81
+ textbox2 = gr.Textbox(placeholder="Enter OpenAPI Key...", lines=1,label='OpenAPI Key')
82
+ with gr.Column():
83
+ btn = gr.Button("Generate")
84
+ output1 = gr.Textbox(lines=2,label='Blog')
85
+
86
+ btn.click(getblog,inputs=[textbox1,textbox2], outputs=[output1])
87
+ examples = gr.Examples(examples=['5G','Minimalism','Rock music'],
88
+ inputs=[textbox1])
89
+
90
+
91
+ demo.launch()