import openai import gradio as gr import os API_TOKEN = os.environ["API_TOKEN"] def chatbot(input,systemInstructions): openai.api_key = API_TOKEN if input: messages = [ {"role": "system", "content": systemInstructions}, ] messages.append({"role": "user", "content": input}) chat = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=messages, temperature=0.8, top_p=0.3, n=1, max_tokens = 1024, presence_penalty = 0.5, frequency_penalty = 0.5, #logit_bias ) reply = chat.choices[0].message.content messages.append({"role": "assistant", "content": reply}) return reply def emojobot(input): generatedKnowledgeCorpus = """ MODEL RAM SS Motor type DC Brushless Motor power 750W Rated Voltage 48 V Maximum speed 20 MPH Battery range 30Miles Battery charging time 4 - 6hours Battery type Lithium-Ion Battery capacity 48V/10.4Ah Dimensions (inch) 67L x 24 W x 45 H Dimensions folded 39L x 18 W x 26H Frame Aluminum-foldable Max. user weight 230 lbs Vehicle weight 55 lbs (with battery) Transmission type Shimano 7-Speed Front brake type Tektro-Disc Rear brake type Tektro-Disc Tire size 20" x 4" MODEL LYNX PRO 750 Motor type DC Brushless Motor power 750W Rated Voltage 48 V Maximum speed 20 MPH Battery range 30 Miles Battery charging time 4 - 6hours Battery type Lithium-Ion Battery capacity 48V/10.4Ah Dimensions (inch) 67L x 24 W x 45 H Dimensions folded 39L x 18 W x 26H Frame Aluminum-foldable Max. user weight 230 lbs Vehicle weight 55 lbs (with battery) Transmission type Shimano Altus 7-Speed Front brake type Tektro-Disc Rear brake type Tektro-Disc Tire size 20" x 4" MODEL WILDCAT PRO 750 Motor type DC Brushless Motor power 750W Rated Voltage 48V Maximum speed 20 MPH Battery range 30 Miles Battery charging time 4-6 hours Battery type Lithium-Ion Battery capacity 48V/10.4 Ah Dimensions (inch) 78L x 25W x 43H Frame Aluminum-Rigid Max.user weight 330 lbs Transmission type Shimano 7-Speed Front brake type hydraulic brake Rear brake type hydraulic brake Tire size 26" x 4" MODEL WILDCAT Motor type DC Brushless Motor power 500W Rated Voltage 48V Maximum speed 20 MPH Battery range 30 Miles Battery charging time 4-6 hours Battery type Lithium-Ion Battery capacity 48V/10.4 Ah Dimensions (inch) 78L x 25W x 43H Frame Aluminum-Rigid Max.user weight 330 lbs Transmission type Shimano 7-Speed Front brake type hydraulic brake Rear brake type hydraulic brake Tire size 26" x 4" MODEL RAM SS Motor type DC Brushless Motor power 750W Rated Voltage 48 V Maximum speed 20 MPH Battery range 30Miles Battery charging time 4 - 6hours Battery type Lithium-Ion Battery capacity 48V/10.4Ah Dimensions (inch) 67L x 24 W x 45 H Dimensions folded 39L x 18 W x 26H Frame Aluminum-foldable Max. user weight 230 lbs Vehicle weight 55 lbs (with battery) Transmission type Shimano 7-Speed Front brake type Tektro-Disc Rear brake type Tektro-Disc Tire size 20" x 4" MODEL LYNX PRO SPORT Motor type DC Brushless Motor power 500W Rated Voltage 48 V Maximum speed 20 MPH Battery range 30Miles Battery charging time 4 - 6hours Battery type Lithium-Ion Battery capacity 48V/10.4Ah Dimensions (inch) 67L x 24 W x 45 H Dimensions folded 39L x 18 W x 26H Frame Aluminum-foldable Max. user weight 230 lbs Vehicle weight 55 lbs (with battery) Transmission type Shimano 7-Speed Front brake type Tektro-Disc Rear brake type Tektro-Disc Tire size 20" x 4" """ generatedKnowledgeCorpus = generatedKnowledgeCorpus.replace("\n","") systemInstructions = "You are a customer who purchased emojo bike and will write excellent customer reviews. Use the following text and write. '\ " systemInstructions = systemInstructions + '\n\n' + generatedKnowledgeCorpus response = chatbot(input, systemInstructions) return response inputs = gr.inputs.Textbox(label="Bike Series for Review") outputs = gr.outputs.Textbox(label="Customer Review") with gr.Blocks() as demo: gr.Markdown( """ # Emojo Service| In Development """ ) responseBox = gr.Interface(fn=emojobot, inputs=[inputs], outputs=outputs, allow_flagging='never') if __name__ == "__main__": demo.launch()