Commit
·
411d537
1
Parent(s):
de697ba
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,15 @@ import gradio as gr
|
|
3 |
import numpy as np
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig,BitsAndBytesConfig
|
5 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
Medical_finetunned_model = "truongghieu/deci-finetuned_Prj2"
|
8 |
answer_text = "This is an answer"
|
@@ -54,9 +63,18 @@ def recognize_speech(audio_data):
|
|
54 |
return f"Could not request results from Google Speech Recognition service; {e}"
|
55 |
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
with gr.Blocks() as demo:
|
58 |
with gr.Row():
|
59 |
-
inp_text = gr.Textbox(label="Input Text")
|
60 |
inp = gr.Audio(type="numpy")
|
61 |
out_text_predict = gr.Textbox(label="Recognized Speech")
|
62 |
button = gr.Button("Recognize Speech" , size="lg")
|
@@ -69,9 +87,13 @@ with gr.Blocks() as demo:
|
|
69 |
with gr.Row():
|
70 |
temperature_slider = gr.Slider(minimum=0, maximum=1, step=0.1, label="temperature",value=0.5)
|
71 |
repetition_penalty_slider = gr.Slider(minimum=0, maximum=2, step=0.1, label="repetition penalty",value=1.0)
|
72 |
-
max_new_tokens_slider = gr.Slider(minimum=0, maximum=
|
73 |
with gr.Row():
|
74 |
out_answer = gr.Textbox(label="Answer")
|
75 |
button_answer = gr.Button("Answer")
|
76 |
button_answer.click(generate_text, [out_text_predict, penalty_alpha_slider, do_sample_checkbox, top_k_slider, temperature_slider, repetition_penalty_slider, max_new_tokens_slider], out_answer)
|
|
|
|
|
|
|
|
|
77 |
demo.launch()
|
|
|
3 |
import numpy as np
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig,BitsAndBytesConfig
|
5 |
import torch
|
6 |
+
from dotenv import load_dotenv
|
7 |
+
import os
|
8 |
+
import openai
|
9 |
+
|
10 |
+
# GPT config in .env file
|
11 |
+
load_dotenv()
|
12 |
+
key = os.environ.get('OPENAI_API_KEY')
|
13 |
+
openai.api_key = key
|
14 |
+
|
15 |
|
16 |
Medical_finetunned_model = "truongghieu/deci-finetuned_Prj2"
|
17 |
answer_text = "This is an answer"
|
|
|
63 |
return f"Could not request results from Google Speech Recognition service; {e}"
|
64 |
|
65 |
|
66 |
+
def pgt_generate(text):
|
67 |
+
response = openai.Completion.create(
|
68 |
+
model = "gpt-3.5-turbo",
|
69 |
+
messages = text,
|
70 |
+
temperature = 0.2,
|
71 |
+
)
|
72 |
+
response_msg = response.choices[0].message.content
|
73 |
+
return response_msg
|
74 |
+
|
75 |
+
|
76 |
with gr.Blocks() as demo:
|
77 |
with gr.Row():
|
|
|
78 |
inp = gr.Audio(type="numpy")
|
79 |
out_text_predict = gr.Textbox(label="Recognized Speech")
|
80 |
button = gr.Button("Recognize Speech" , size="lg")
|
|
|
87 |
with gr.Row():
|
88 |
temperature_slider = gr.Slider(minimum=0, maximum=1, step=0.1, label="temperature",value=0.5)
|
89 |
repetition_penalty_slider = gr.Slider(minimum=0, maximum=2, step=0.1, label="repetition penalty",value=1.0)
|
90 |
+
max_new_tokens_slider = gr.Slider(minimum=0, maximum=200, step=1, label="max new tokens",value=30)
|
91 |
with gr.Row():
|
92 |
out_answer = gr.Textbox(label="Answer")
|
93 |
button_answer = gr.Button("Answer")
|
94 |
button_answer.click(generate_text, [out_text_predict, penalty_alpha_slider, do_sample_checkbox, top_k_slider, temperature_slider, repetition_penalty_slider, max_new_tokens_slider], out_answer)
|
95 |
+
with gr.Row():
|
96 |
+
gpt_output = gr.Textbox(label="GPT-3.5 Turbo Output")
|
97 |
+
button_gpt = gr.Button("GPT-3.5 Answer")
|
98 |
+
button_gpt.click(pgt_generate,out_text_predict,gpt_output)
|
99 |
demo.launch()
|