File size: 2,369 Bytes
926b66c
d13d3d0
db69a9f
d00c057
d13d3d0
fc7bcef
98434e4
bcff98b
fc7bcef
 
 
 
2511499
25b98ee
c66c05d
ef69bbd
84244d1
b18c4a7
 
c2f51da
b314df6
5df322f
 
244de22
 
fc7bcef
3aa2227
fc7bcef
 
bcff98b
 
 
 
 
 
 
 
 
fc7bcef
 
bcff98b
 
 
 
 
 
 
 
 
 
 
 
8ed8b62
 
bcff98b
4cf801e
dd7e3c9
8ed8b62
b906730
 
bcff98b
 
dd7e3c9
ad81e83
3aa2227
dd7e3c9
bcff98b
 
d9cc1af
fc7bcef
5356743
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import openai
import gradio as gr


# Set up OpenAI API credentials
api_key = os.environ.get("OPENAI_API_KEY")
openai.api_key = api_key

# Define a function to generate a response to user input
def generate_response(user_input):
    if "who created you" in user_input.lower():
        chat_response = "I was created by Ram.V"
    elif "who is superstar" in user_input.lower():
        chat_response =  "The one and only * Superstar Rajinikanth * Thalaiva!"
    elif "what's on 10th aug" in user_input.lower():
        chat_response =  "Jailer Movie releasing! Alappara Kelappurom Thalaivaru Nerandharam!"
    elif "what is the weather like" in user_input.lower():
        chat_response = "I'm sorry, but I don't have the ability to check the weather. Is there something else I can help you with?"
    elif "how are you" in user_input.lower(): 
        chat_response = "I'm a chatbot created by Ram.V. I don't have feelings, but thanks for asking. Hope you're well! :-)"
    elif "what's your name" in user_input.lower(): 
        chat_response = "My name is ChatRobo :-)"
    else:
        prompt = f"You said: {user_input}"

        
        # Generate a response using the OpenAI API
        response = openai.Completion.create(
            model="text-davinci-003",
            prompt=prompt,
            temperature=0.9,
            max_tokens=150,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0.6,
            stop=["Human:", "AI:"]
        )

        # Extract the response from the API output
        chat_response = response.choices[0].text.strip()

    return chat_response

# Define the function to handle the chat history
def openai_chat_history(input, history):
    history = history or []
    if input.strip() != "":
        s = list(sum(history, ()))
        s.append(input)
        inp = ' '.join(s)
        output = generate_response(inp)
        history.append((input, output))
        return history[-1][1]
    else:
        return ""

# Define the conversation prompt
conversation_prompt = "Welcome to ChatRobo, kindly type in your enquiries: "

# Set up the Gradio interface
block = gr.Interface(
    fn=openai_chat_history, 
    inputs=[gr.inputs.Textbox(placeholder=conversation_prompt)], 
    outputs=[gr.outputs.Textbox(label="ChatRobo Output")]
)

# Launch the Gradio interface
block.launch()