Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def Txt_Generation(prompt, model,temperature, api_key):
|
| 6 |
+
if api_key == '':
|
| 7 |
+
output= gr.Textbox("*** Please provide API Key ***")
|
| 8 |
+
else:
|
| 9 |
+
try:
|
| 10 |
+
messages = [{"role": "user", "content": prompt}]
|
| 11 |
+
client = OpenAI(api_key=api_key)
|
| 12 |
+
response = client.chat.completions.create(
|
| 13 |
+
model=model,
|
| 14 |
+
temperature=temperature,
|
| 15 |
+
messages=messages )
|
| 16 |
+
output = response.choices[0].message.content
|
| 17 |
+
except :
|
| 18 |
+
output = gr.Textbox("*** Please check your API-Key and try again ***")
|
| 19 |
+
return output
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
models = ["gpt-3.5-turbo-1106","gpt-4-0613","gpt-4-32k-0613" ]
|
| 23 |
+
|
| 24 |
+
title = "Enter your Prompt"
|
| 25 |
+
description = """<img src = "https://upload.wikimedia.org/wikipedia/commons/4/4d/OpenAI_Logo.svg" width=300px>
|
| 26 |
+
# Provide OpenAI API Key, select your model
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
gr.Interface(
|
| 30 |
+
Txt_Generation,
|
| 31 |
+
[
|
| 32 |
+
gr.Textbox(label="Enter your Prompt",),
|
| 33 |
+
gr.Dropdown(models, label="choose your Model", value= "gpt-3.5-turbo-1106" ),
|
| 34 |
+
gr.Slider(minimum=0.1, maximum=1, step=0.1),
|
| 35 |
+
gr.Textbox(type = 'password',label="Enter your API-Key", placeholder="API-Key", lines=1),
|
| 36 |
+
]
|
| 37 |
+
,outputs="text",
|
| 38 |
+
title=title,
|
| 39 |
+
description=description,
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
).launch()
|