Spaces:
Runtime error
Runtime error
KashiwaByte
commited on
Commit
•
6d0fdd1
1
Parent(s):
4a0cca8
app requirements commit
Browse files- app.py +72 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
import openai, subprocess
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
# 换成你自己的api_key
|
7 |
+
openai.api_key = "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"
|
8 |
+
debatestyle = " "
|
9 |
+
messages = [{"role": "system", "content": '你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我'}]
|
10 |
+
chat_transcript = ""
|
11 |
+
def transcribe(audio):
|
12 |
+
global messages
|
13 |
+
global chat_transcript
|
14 |
+
|
15 |
+
myfile=Path(audio)
|
16 |
+
myfile=myfile.rename(myfile.with_suffix('.wav'))
|
17 |
+
audio_file = open(myfile,"rb")
|
18 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
19 |
+
|
20 |
+
messages.append({"role": "user", "content": transcript["text"]})
|
21 |
+
|
22 |
+
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
23 |
+
|
24 |
+
system_message = response["choices"][0]["message"]
|
25 |
+
# print(response)
|
26 |
+
messages.append(system_message)
|
27 |
+
|
28 |
+
subprocess.call(["wsay", system_message['content']])
|
29 |
+
|
30 |
+
chat_transcript = ""
|
31 |
+
for message in messages:
|
32 |
+
if message['role'] != 'system':
|
33 |
+
chat_transcript += message['role'] + ": " + message['content'] + "\n\n"
|
34 |
+
|
35 |
+
return chat_transcript
|
36 |
+
|
37 |
+
def eraser():
|
38 |
+
global messages
|
39 |
+
messages = [{"role": "system", "content": '你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我,每次回答不超过100个字'}]
|
40 |
+
print('擦除成功✏️🧽')
|
41 |
+
|
42 |
+
def initway(api_key,style):
|
43 |
+
openai.api_key =api_key
|
44 |
+
|
45 |
+
debatestyle = style
|
46 |
+
print("初始化成功!🎉")
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as init:
|
51 |
+
with gr.Row():
|
52 |
+
api_key = gr.Textbox(
|
53 |
+
lines=1, placeholder="api_key Here...", label="api_key",value="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")
|
54 |
+
style = gr.Textbox(
|
55 |
+
lines=1, placeholder="style Here...", label="辩风" ,value="你是一名逻辑性很强的资深辩手,你擅长通过数据论据和学理论据来反驳,你的反驳总是一阵见血,而且很有逻辑性。接下来我会提出我的观点,你需要做的就是针锋相对地反驳我,每次回答不超过100个字")
|
56 |
+
btn = gr.Button(value="初始化")
|
57 |
+
btn.click(initway, [api_key, style])
|
58 |
+
|
59 |
+
with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as Debate:
|
60 |
+
with gr.Row():
|
61 |
+
audio=gr.Audio(source="microphone", type="filepath",label="语音输入")
|
62 |
+
trans = gr.Button("🎭 转录")
|
63 |
+
output_button = gr.Button("重置🧽")
|
64 |
+
with gr.Row():
|
65 |
+
output_transcript = gr.Textbox(label="语音转录输出")
|
66 |
+
trans.click(transcribe, [audio],[output_transcript])
|
67 |
+
output_button.click(eraser)
|
68 |
+
|
69 |
+
test=gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text")
|
70 |
+
|
71 |
+
ui = gr.TabbedInterface([init,Debate,test],["初始化","辩论","测试"])
|
72 |
+
ui.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==3.44.0
|
2 |
+
openai==0.28.0
|