Seicas commited on
Commit
cd2255e
·
verified ·
1 Parent(s): 943023c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -47
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, Depends, HTTPException, Security, status, UploadFile, File
2
  from fastapi.middleware.cors import CORSMiddleware
3
  import gradio as gr
4
  import os
@@ -29,6 +29,52 @@ try:
29
  except OSError:
30
  nlp = spacy.blank("tr")
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  # FastAPI uygulaması
33
  app = FastAPI(title="Pediatrik ASR API")
34
 
@@ -76,52 +122,9 @@ async def transcribe_audio_api(
76
  except Exception as e:
77
  raise HTTPException(status_code=500, detail=str(e))
78
 
79
- # Gradio wrapper fonksiyonu
80
- def transcribe_gr(audio_file, diarize=True, enhance_audio=True, anonymize=True):
81
- """Ses dosyasını transkribe eder"""
82
- try:
83
- if audio_file is None:
84
- return "Lütfen bir ses dosyası yükleyin."
85
-
86
- asr_model = get_asr_model()
87
- result = asr_model.transcribe(
88
- audio_file,
89
- speaker_diarization=diarize,
90
- enhance_audio=enhance_audio
91
- )
92
-
93
- output = "📝 Transkripsiyon:\n\n"
94
-
95
- if "diarization" in result:
96
- for segment in result["diarization"]:
97
- output += f"🗣️ {segment['speaker']} ({segment['start']:.1f}s - {segment['end']:.1f}s):\n"
98
- output += f"{segment['text']}\n\n"
99
- else:
100
- output += result["text"]
101
-
102
- if result.get("anonymized"):
103
- output += "\n🔒 Kişisel veriler anonimleştirildi."
104
-
105
- return output
106
- except Exception as e:
107
- return f"Bir hata oluştu: {str(e)}"
108
-
109
- # Gradio arayüzü
110
- demo = gr.Interface(
111
- fn=transcribe_gr,
112
- inputs=[
113
- gr.Audio(type="filepath", label="Ses Dosyası"),
114
- gr.Checkbox(label="Konuşmacı Ayrımı", value=True),
115
- gr.Checkbox(label="Ses İyileştirme", value=True),
116
- gr.Checkbox(label="Kişisel Verileri Anonimleştir", value=True)
117
- ],
118
- outputs=gr.Textbox(label="Transkripsiyon Sonucu", lines=10),
119
- title="🏥 Tıbbi Konuşma Transkripsiyon Servisi",
120
- description="Bu servis, doktor vizitelerindeki konuşmaları yazıya döker ve konuşmacıları ayırt eder."
121
- )
122
-
123
- # Gradio'yu FastAPI'ye mount et
124
- app.mount("/", demo.app)
125
 
126
  # Uygulamayı başlat
127
  if __name__ == "__main__":
 
1
+ from fastapi import FastAPI, Depends, HTTPException, status, UploadFile, File
2
  from fastapi.middleware.cors import CORSMiddleware
3
  import gradio as gr
4
  import os
 
29
  except OSError:
30
  nlp = spacy.blank("tr")
31
 
32
+ # Gradio arayüzü
33
+ def create_gradio_app():
34
+ def transcribe_gr(audio_file, diarize=True, enhance_audio=True, anonymize=True):
35
+ try:
36
+ if audio_file is None:
37
+ return "Lütfen bir ses dosyası yükleyin."
38
+
39
+ asr_model = get_asr_model()
40
+ result = asr_model.transcribe(
41
+ audio_file,
42
+ speaker_diarization=diarize,
43
+ enhance_audio=enhance_audio
44
+ )
45
+
46
+ output = "📝 Transkripsiyon:\n\n"
47
+
48
+ if "diarization" in result:
49
+ for segment in result["diarization"]:
50
+ output += f"🗣️ {segment['speaker']} ({segment['start']:.1f}s - {segment['end']:.1f}s):\n"
51
+ output += f"{segment['text']}\n\n"
52
+ else:
53
+ output += result["text"]
54
+
55
+ if result.get("anonymized"):
56
+ output += "\n🔒 Kişisel veriler anonimleştirildi."
57
+
58
+ return output
59
+ except Exception as e:
60
+ return f"Bir hata oluştu: {str(e)}"
61
+
62
+ demo = gr.Interface(
63
+ fn=transcribe_gr,
64
+ inputs=[
65
+ gr.Audio(type="filepath", label="Ses Dosyası"),
66
+ gr.Checkbox(label="Konuşmacı Ayrımı", value=True),
67
+ gr.Checkbox(label="Ses İyileştirme", value=True),
68
+ gr.Checkbox(label="Kişisel Verileri Anonimleştir", value=True)
69
+ ],
70
+ outputs=gr.Textbox(label="Transkripsiyon Sonucu", lines=10),
71
+ title="🏥 Tıbbi Konuşma Transkripsiyon Servisi",
72
+ description="Bu servis, doktor vizitelerindeki konuşmaları yazıya döker ve konuşmacıları ayırt eder.",
73
+ theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="blue"),
74
+ allow_flagging="never"
75
+ )
76
+ return demo
77
+
78
  # FastAPI uygulaması
79
  app = FastAPI(title="Pediatrik ASR API")
80
 
 
122
  except Exception as e:
123
  raise HTTPException(status_code=500, detail=str(e))
124
 
125
+ # Gradio uygulamasını oluştur ve mount et
126
+ gradio_app = create_gradio_app()
127
+ app = gr.mount_gradio_app(app, gradio_app, path="/")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  # Uygulamayı başlat
130
  if __name__ == "__main__":