PyGuru_Chatbot / file1_chatgpt.py
Daevesh's picture
Upload file1_chatgpt.py
af64795
raw
history blame
1.24 kB
# -*- coding: utf-8 -*-
"""File1_chatgpt.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ips60VEBlb1HaAsIsz41BfMWXUBjNlsG
"""
!pip install openai
!pip install gradio
import os
import openai
openai.api_key="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"
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0,
)
return response.choices[0].message["content"]
import gradio as gr
# Variable to store the user input
user_input = ""
def store_string(input_string,history):
# Store the input_string in the global variable
global user_input
return get_completion(input_string)
# Create an interface with a text input and a submit button
#interface = gr.Interface(fn=store_string, inputs=gr.inputs.Textbox(), outputs="text", allow_flagging= "auto")
interface =gr.ChatInterface(store_string,analytics_enabled=True)
interface.launch(share=True, inbrowser= True, auth = ('rrr','#la_rocks'), auth_message= "Enter your username and password that you received in on LA group")