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()