Upload 2 files
Browse files- app.py +42 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
with gr.Blocks() as demo:
|
| 5 |
+
def Chat_bot(prompt, history, api_key):
|
| 6 |
+
if api_key == '':
|
| 7 |
+
output= "Please provide API Key"
|
| 8 |
+
else:
|
| 9 |
+
try:
|
| 10 |
+
messages = [{"role": "system", "content": "you are an English teaching chatbot who replies everything in both English and Korean. but each line should be in English and Korean."}, {"role": "user", "content": prompt}]
|
| 11 |
+
client = OpenAI(api_key= api_key )
|
| 12 |
+
response = client.chat.completions.create(
|
| 13 |
+
model="ft:gpt-3.5-turbo-0613:personal::8fjNPFEp",
|
| 14 |
+
messages=messages,
|
| 15 |
+
temperature=0 )
|
| 16 |
+
output = response.choices[0].message.content
|
| 17 |
+
except :
|
| 18 |
+
output = "Please check your API-Key and try again"
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
gr.Markdown(
|
| 25 |
+
"""
|
| 26 |
+
# Fine-tuned English training ChatGPT model.
|
| 27 |
+
|
| 28 |
+
<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px>
|
| 29 |
+
|
| 30 |
+
# Please provide API-Key and start the class
|
| 31 |
+
|
| 32 |
+
""")
|
| 33 |
+
|
| 34 |
+
gr.ChatInterface(Chat_bot,
|
| 35 |
+
additional_inputs=[
|
| 36 |
+
gr.Textbox( type = 'password', label="Enter your API-Key", placeholder="API-Key", lines=1)
|
| 37 |
+
]
|
| 38 |
+
)
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
|
| 41 |
+
demo.launch()
|
| 42 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai
|