File size: 816 Bytes
7b664dc
 
 
 
 
 
 
f9b26a5
7b664dc
f3a7387
 
 
 
 
7b664dc
 
27b9508
7b664dc
 
 
 
27b9508
6d847d3
7b664dc
27b9508
 
7b664dc
 
 
 
 
2b76f64
 
7b664dc
 
 
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
#!/usr/bin/env python
# coding: utf-8

import os
import openai
import gradio as gr

openai.api_key = os.getenv('openaikey')

def predict(input, manual_query_repacement, history=[]):

    if manual_query_repacement != "":
        input = manual_query_repacement
    
    response = openai.Completion.create(
    model="text-davinci-003",
    prompt=input,
    temperature=0.9,
    max_tokens=150,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0.6)
    
    # tokenize the new input sentence
    responseText = response["choices"][0]["text"]
    history.append((input, responseText))

    return history, history


gr.Interface(fn=predict,
             inputText= gradio.Textbox(value="tmp")
             inputs=[inputText,"text",'state'],
            
             outputs=["chatbot",'state']).launch()