Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
import random
|
5 |
+
|
6 |
+
API_TOKEN='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'
|
7 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
|
9 |
+
|
10 |
+
|
11 |
+
prompt="""What would this look like in 2050? Give 5 optimally describing bigrams.
|
12 |
+
Input:cake shop
|
13 |
+
Output:Sustainable ingredients,Virtual reality experience,Customizable flavor options,3D printed designs,Robotic assistants
|
14 |
+
#####
|
15 |
+
Input:consulting firm
|
16 |
+
Output:Virtual meetings,AI integration,Sustainability focus,Virtual reality simulations,Blockchain technology
|
17 |
+
#####
|
18 |
+
Input:biscuit brand
|
19 |
+
Output:Sustainable packaging,Plant-based ingredients,Digital marketing,Virtual reality,Smart packaging
|
20 |
+
#####
|
21 |
+
"""
|
22 |
+
|
23 |
+
|
24 |
+
def query(text):
|
25 |
+
#global prompt
|
26 |
+
print(text)
|
27 |
+
text = prompt+"\nInput:"+text + "\nOutput:"
|
28 |
+
#print(text)
|
29 |
+
payload = {
|
30 |
+
"inputs": text,
|
31 |
+
"parameters": {
|
32 |
+
"max_length": 250,
|
33 |
+
"temperature": 0.9,
|
34 |
+
"seed":random.randint(0, 100),
|
35 |
+
},
|
36 |
+
}
|
37 |
+
|
38 |
+
data = json.dumps(payload)
|
39 |
+
response = requests.request("POST", API_URL, headers=headers, data=data)
|
40 |
+
#print('Response here\n',response.content)
|
41 |
+
generated_text=json.loads(response.content.decode("utf-8"))[0]['generated_text']
|
42 |
+
result = generated_text.replace(text,'').strip()
|
43 |
+
result = result.replace("Output:","")
|
44 |
+
parts = result.split("###")
|
45 |
+
topic = parts[0].strip()
|
46 |
+
topic=topic.split("Input:")[0]
|
47 |
+
print(topic)
|
48 |
+
return topic
|
49 |
+
|
50 |
+
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown("<h1><center>Ideas of the Future</center></h1>")
|
53 |
+
gr.Markdown(
|
54 |
+
"""ChatGPT based Insights from Decodem.ai for businesses.\nWhile ChatGPT has multiple use cases we have evolved specific use cases/ templates for businesses \n\n This template provides ideas on how a business would look like in the future. Enter a business area and get the results."""
|
55 |
+
)
|
56 |
+
textbox = gr.Textbox(placeholder="Enter business type here...", lines=1,label='Yourbusiness area')
|
57 |
+
btn = gr.Button("Generate")
|
58 |
+
output1 = gr.Textbox(lines=2,label='The future')
|
59 |
+
|
60 |
+
btn.click(query,inputs=[textbox], outputs=[output1])
|
61 |
+
examples = gr.Examples(examples=['icecream parlor','space travel','book shop','ecommerce','grocery delivery'],
|
62 |
+
inputs=[textbox])
|
63 |
+
|
64 |
+
|
65 |
+
demo.launch()
|