decodemai commited on
Commit
af41982
1 Parent(s): 52116b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import requests
3
+ import gradio as gr
4
+ import random
5
+ import time
6
+ import os
7
+
8
+ API_TOKEN = os.getenv("API_TOKEN")
9
+ from huggingface_hub import InferenceApi
10
+ inference = InferenceApi("bigscience/bloom",token=API_TOKEN)
11
+
12
+ prompt="""
13
+ 4 futuristic ideas for the intersection of
14
+ Input: finance & blockchain
15
+ Output:
16
+ Decentralized stock trading platform: The use of blockchain technology to create a decentralized stock trading platform where users can buy and sell stocks without the need for a middleman. This could greatly reduce transaction costs and increase the security and transparency of the trading process.
17
+ Cryptocurrency-based loans: The use of blockchain technology to create a decentralized lending platform where users can borrow and lend using cryptocurrencies. This could greatly reduce the costs and barriers of traditional lending and make it more accessible to a wider range of borrowers.
18
+ Digital asset management: The use of blockchain technology to create a digital asset management platform where users can securely and transparently manage their digital assets such as cryptocurrencies, stocks, and other financial instruments.
19
+ Smart contract-based insurance: The use of blockchain technology to create smart contract-based insurance policies that automatically execute payouts in the event of a claim. This could greatly reduce the need for human intervention and increase the speed and efficiency of the claims process.
20
+ ###
21
+ Input:ai & website
22
+ Output:
23
+ Personalized product recommendations: An AI-powered algorithm that analyzes customer browsing and purchase history to make personalized product recommendations on the website. This can help increase customer engagement and sales.
24
+ Chatbot customer service: An AI chatbot that can answer customer questions and provide assistance on the website. This can reduce the workload on customer service representatives and provide 24/7 assistance to customers.
25
+ Real-time language translation: An AI-powered tool that can automatically translate website content into multiple languages in real-time. This can help increase website accessibility and reach a global audience.
26
+ Smart search: An AI-powered search feature that can understand natural language queries and provide accurate and relevant results. This can improve the user experience and make it easier for customers to find the products they are looking for.
27
+ ###
28
+ Input:car & bike
29
+ Output:
30
+ Smart bike lanes: In this scenario, car and bike traffic would be separated by smart bike lanes that use sensors and cameras to detect and alert drivers to the presence of bicycles. The smart bike lanes would also have the ability to change the speed limit for cars depending on the number of bicycles present, creating a safer and more efficient flow of traffic.
31
+ Autonomous bike-sharing: In this scenario, autonomous cars would be used to transport bicycles to designated bike-sharing stations. This would allow for a more efficient bike-sharing system, as the cars would be able to navigate to the closest available station and drop off the bicycles without the need for human intervention.
32
+ Intelligent traffic signals: In this scenario, traffic signals would be equipped with cameras and sensors that detect the presence of bicycles and adjust the timing of the lights accordingly. This would allow for a more efficient flow of traffic and reduce the risk of collisions between cars and bicycles.
33
+ Augmented reality bike navigation: In this scenario, cyclists would use augmented reality technology to navigate through the city. This would allow for a more intuitive and efficient navigation experience, as the cyclist would be able to see virtual signs and arrows overlaid on the real world, indicating the best route to take. Additionally, the technology would be able to alert the cyclist of potential hazards such as cars and other bicycles, making it safer for everyone.
34
+ ###"""
35
+
36
+ def infer(prompt,
37
+ max_length = 250,
38
+ top_k = 0,
39
+ num_beams = 0,
40
+ no_repeat_ngram_size = 2,
41
+ top_p = 0.9,
42
+ seed=42,
43
+ temperature=0.7,
44
+ greedy_decoding = False,
45
+ return_full_text = False):
46
+
47
+ print(seed)
48
+ top_k = None if top_k == 0 else top_k
49
+ do_sample = False if num_beams > 0 else not greedy_decoding
50
+ num_beams = None if (greedy_decoding or num_beams == 0) else num_beams
51
+ no_repeat_ngram_size = None if num_beams is None else no_repeat_ngram_size
52
+ top_p = None if num_beams else top_p
53
+ early_stopping = None if num_beams is None else num_beams > 0
54
+
55
+ params = {
56
+ "max_new_tokens": max_length,
57
+ "top_k": top_k,
58
+ "top_p": top_p,
59
+ "temperature": temperature,
60
+ "do_sample": do_sample,
61
+ "seed": seed,
62
+ "early_stopping":early_stopping,
63
+ "no_repeat_ngram_size":no_repeat_ngram_size,
64
+ "num_beams":num_beams,
65
+ "return_full_text":return_full_text
66
+ }
67
+
68
+ s = time.time()
69
+ response = inference(prompt, params=params)
70
+ #print(response)
71
+ proc_time = time.time()-s
72
+ #print(f"Processing time was {proc_time} seconds")
73
+ return response
74
+
75
+ def getideas(text_inp):
76
+
77
+ text = prompt+"\nInput:"+text_inp + "\nOutput:"
78
+ resp = infer(text,seed=random.randint(0,100))
79
+
80
+ generated_text=resp[0]['generated_text']
81
+ result = generated_text.replace(text,'').strip()
82
+ result = result.replace("Output:","")
83
+ parts = result.split("###")
84
+ topic = parts[0].strip()
85
+ topic="\n".join(topic.split('\n'))
86
+ return(topic)
87
+
88
+
89
+ with gr.Blocks() as demo:
90
+ gr.Markdown("<h1><center>Scenarios for Your Business</center></h1>")
91
+ gr.Markdown(
92
+ """ChatGPT based Insights from <a href="https://www.decodem.ai">Decodem.ai</a> 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 two intersecting trends/ areas and get the results. Use examples to guide. We use a equally powerful AI model bigscience/bloom."""
93
+ )
94
+ textbox = gr.Textbox(placeholder="Enter business type here...", lines=1,label='Your business area')
95
+ btn = gr.Button("Generate")
96
+ output1 = gr.Textbox(lines=2,label='The future')
97
+
98
+ btn.click(getideas,inputs=[textbox], outputs=[output1])
99
+ examples = gr.Examples(examples=['icecream parlor','space travel','book shop','ecommerce','grocery delivery'],
100
+ inputs=[textbox])
101
+
102
+
103
+ demo.launch()