Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
|
5 |
+
OPENAI_API_KEY = os.getenv("API_KEY")
|
6 |
+
API_URL = os.getenv("BASE_URL")
|
7 |
+
|
8 |
+
def generate_response(prompt):
|
9 |
+
headers = {
|
10 |
+
'Content-Type': 'application/json',
|
11 |
+
'Authorization': f'Bearer {OPENAI_API_KEY}',
|
12 |
+
}
|
13 |
+
|
14 |
+
data = {
|
15 |
+
'model': 'gpt-3.5-turbo',
|
16 |
+
'prompt': prompt,
|
17 |
+
'max_tokens': 150,
|
18 |
+
}
|
19 |
+
|
20 |
+
response = requests.post(API_URL, json=data, headers=headers)
|
21 |
+
response_data = response.json()
|
22 |
+
generated_text = response_data['choices'][0]['text'].strip()
|
23 |
+
|
24 |
+
return generated_text
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=generate_response,
|
28 |
+
inputs=gr.Textbox(),
|
29 |
+
outputs=gr.Textbox(),
|
30 |
+
live=True,
|
31 |
+
capture_session=True,
|
32 |
+
)
|
33 |
+
|
34 |
+
iface.launch()
|