Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai, config
|
| 3 |
+
openai.api_key = config.OPEN_API_key
|
| 4 |
+
|
| 5 |
+
messages = [{"role": "system", "content": 'You are Python ML developer. reply only in python code'}]
|
| 6 |
+
|
| 7 |
+
def transcribe(text):
|
| 8 |
+
|
| 9 |
+
messages.append({"role": "user", "content": text})
|
| 10 |
+
|
| 11 |
+
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
| 12 |
+
|
| 13 |
+
system_message = response["choices"][0]["message"]
|
| 14 |
+
messages.append(system_message)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
chat_transcript = ""
|
| 19 |
+
for message in messages:
|
| 20 |
+
if message['role'] != 'system':
|
| 21 |
+
chat_transcript += message['role'] + ": " + message['content'] + "\n\n"
|
| 22 |
+
|
| 23 |
+
return chat_transcript
|
| 24 |
+
|
| 25 |
+
ui = gr.Interface(fn=transcribe, inputs="text", outputs="text").launch()
|