Spaces:
Runtime error
Runtime error
Hugo Lindgren commited on
Commit ·
c1b7234
1
Parent(s): 5b92595
aaa
Browse files- app.py +42 -24
- flagged/log.csv +2 -0
app.py
CHANGED
|
@@ -1,39 +1,57 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
#pipe = pipeline(model="jdowling/whisper-small-hi") # change to "your-username/the-name-you-picked"
|
| 7 |
#generator = pipeline('text-generation', model='openai-gpt')
|
| 8 |
#set_seed(42)
|
| 9 |
# Use the API key as needed
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
-
openai.api_key = os.environ.get('OPEN_AI_KEY')
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
{"role": "system", "content": "You are a psychologist."},
|
| 20 |
-
{"role": "user", "content": prompt}
|
| 21 |
-
]
|
| 22 |
-
)
|
| 23 |
-
return response['choices'][0]['message']['content']
|
| 24 |
|
| 25 |
def transcribe(audio):
|
| 26 |
-
prompt = "Im very sad because my dog died."
|
| 27 |
-
response = generate_chat(prompt)
|
| 28 |
#text = pipe(audio)["text"]
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import requests
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
import gradio as gr
|
| 7 |
import os
|
| 8 |
+
import json
|
| 9 |
|
| 10 |
#pipe = pipeline(model="jdowling/whisper-small-hi") # change to "your-username/the-name-you-picked"
|
| 11 |
#generator = pipeline('text-generation', model='openai-gpt')
|
| 12 |
#set_seed(42)
|
| 13 |
# Use the API key as needed
|
| 14 |
|
| 15 |
+
client = OpenAI(
|
| 16 |
+
api_key=os.environ.get('OPEN_AI_KEY')
|
| 17 |
+
|
| 18 |
+
)
|
| 19 |
|
| 20 |
|
|
|
|
| 21 |
|
| 22 |
+
psychologist_url = "https://raw.githubusercontent.com/rogoran/id2223kth.github.io/master/src/serverless-ml-intro/serverless-ml-lab/wine_images/360_F_169387942_tUJn9ADX31sRDFCuK9nlBuRR4gO6a1TK.jpg"
|
| 23 |
+
IMG = Image.open(requests.get(psychologist_url, stream=True).raw)
|
| 24 |
+
latest_messages = [{"role": "system", "content": "Du är en svensktalande psykolog."}]
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def transcribe(audio):
|
|
|
|
|
|
|
| 28 |
#text = pipe(audio)["text"]
|
| 29 |
+
if audio is None:
|
| 30 |
+
return
|
| 31 |
+
#prompt = "Jag är ledsen eftersom jag tappade min klubba."
|
| 32 |
+
print(audio)
|
| 33 |
+
return chat(audio)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def chat(prompt):
|
| 37 |
+
#response = generate_chat(prompt)
|
| 38 |
+
latest_messages.append({"role": "user", "content": prompt})
|
| 39 |
+
response = client.chat.completions.create(
|
| 40 |
+
model="gpt-3.5-turbo-1106",
|
| 41 |
+
messages=latest_messages
|
| 42 |
+
)
|
| 43 |
+
latest_messages.append({"role": "assistant", "content": response.choices[0].message.content})
|
| 44 |
+
return response.choices[0].message.content
|
| 45 |
+
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column():
|
| 49 |
+
#inp = gr.Audio(sources="microphone", type="filepath")
|
| 50 |
+
inp = gr.Textbox()
|
| 51 |
+
btn = gr.Button("Send transcribed msg")
|
| 52 |
+
with gr.Column():
|
| 53 |
+
gr.Image(value=IMG, label="Doctor Amanda")
|
| 54 |
+
out = gr.Textbox(label="Doctor Amandas answers")
|
| 55 |
+
btn.click(fn=transcribe, inputs=inp, outputs=out)
|
| 56 |
+
|
| 57 |
+
demo.launch()
|
flagged/log.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
audio,output,flag,username,timestamp
|
| 2 |
+
,,,,2023-12-03 15:54:26.312403
|