Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +48 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import whisper
|
4 |
+
|
5 |
+
# Setarea cheii OpenAI
|
6 |
+
openai.api_key = "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"
|
7 |
+
|
8 |
+
# Inițializare model Whisper
|
9 |
+
model = whisper.load_model("base")
|
10 |
+
|
11 |
+
# Funcția pentru procesarea audio-ului și generarea rezumatului
|
12 |
+
def proceseaza_audio(file):
|
13 |
+
# Verificăm dacă `file` este un obiect de tip fișier
|
14 |
+
if hasattr(file, 'name'):
|
15 |
+
file_path = file.name
|
16 |
+
else:
|
17 |
+
raise ValueError("Fișierul primit nu este valid. Verifică inputul.")
|
18 |
+
|
19 |
+
# Transcriere folosind modelul Whisper
|
20 |
+
result = model.transcribe(file_path)
|
21 |
+
text = result["text"]
|
22 |
+
|
23 |
+
# Generare rezumat folosind OpenAI
|
24 |
+
response = openai.ChatCompletion.create(
|
25 |
+
model="gpt-4",
|
26 |
+
messages=[
|
27 |
+
{"role": "system", "content": "Ești un asistent care rezumă textul."},
|
28 |
+
{"role": "user", "content": text}
|
29 |
+
]
|
30 |
+
)
|
31 |
+
rezumat = response['choices'][0]['message']['content']
|
32 |
+
return text, rezumat
|
33 |
+
|
34 |
+
# Interfața Gradio
|
35 |
+
inputs = gr.Audio(type="file")
|
36 |
+
outputs = [gr.Textbox(label="Transcrierea textului:"), gr.Textbox(label="Rezumatul textului:")]
|
37 |
+
|
38 |
+
app = gr.Interface(
|
39 |
+
fn=proceseaza_audio,
|
40 |
+
inputs=inputs,
|
41 |
+
outputs=outputs,
|
42 |
+
title="Transcriere și Rezumat AI",
|
43 |
+
description="Această aplicație transcrie fișiere audio și creează un rezumat al conținutului folosind AI."
|
44 |
+
)
|
45 |
+
|
46 |
+
# Rulare aplicație
|
47 |
+
if __name__ == "__main__":
|
48 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.37.0
|
2 |
+
openai
|
3 |
+
torch
|
4 |
+
openai-whisper
|