seawolf2357 commited on
Commit
dbe02a3
·
verified ·
1 Parent(s): e78a23f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,22 +1,26 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # 감정 분석 파이프라인을 생성합니다.
5
- sentiment_pipeline = pipeline("sentiment-analysis")
6
 
7
- def analyze_sentiment(text):
8
- # 입력된 텍스트에 대한 감정 분석을 수행합니다.
9
- result = sentiment_pipeline(text)
10
- # 분석 결과를 반환합니다.
11
- return result[0]
 
 
12
 
13
- # Gradio 인터페이스를 생성합니다.
14
- interface = gr.Interface(fn=analyze_sentiment,
15
- inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
16
- outputs="json",
17
- title="Text Sentiment Analysis",
18
- description="Enter a piece of text to analyze its sentiment. The model will classify it as positive or negative.")
 
 
19
 
20
- # 앱을 실행합니다.
21
  if __name__ == "__main__":
22
- interface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # 비전 인식 파이프라인 초기화
5
+ vision_pipeline = pipeline(task="image-classification")
6
 
7
+ def process_video(video):
8
+ # 비디오 프레임을 처리하고 비전 인식 모델을 적용하는 함수
9
+ # 여기서는 예시를 단순화하기 위해 비디오 파일의 첫 프레임만 처리합니다.
10
+ # 실제 애플리케이션에서는 비디오의 모든 프레임 또는 특정 인터벌로 프레임을 처리할 수 있습니다.
11
+ results = vision_pipeline(video)
12
+ labels = [result['label'] for result in results]
13
+ return ", ".join(labels)
14
 
15
+ # Gradio 인터페이스 정의
16
+ iface = gr.Interface(
17
+ fn=process_video,
18
+ inputs=gr.Video(source="webcam", streaming=True),
19
+ outputs="text",
20
+ title="실시간 웹캠 모니터링과 비전 인식",
21
+ description="웹캠을 통해 실시간으로 화면 변화를 감지하고, 비전 인식 모델을 적용하여 텍스트로 출력합니다."
22
+ )
23
 
24
+ # Gradio 애플리케이션 실행
25
  if __name__ == "__main__":
26
+ iface.launch()