Hanjaewon commited on
Commit
8bda67b
ยท
verified ยท
1 Parent(s): 5aaf9f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -22
app.py CHANGED
@@ -1,31 +1,20 @@
1
  import gradio as gr
2
- from transformers import T5ForConditionalGeneration, T5Tokenizer
3
- import torch
4
 
5
- # Hugging Face์˜ t5-base ๋ชจ๋ธ ๋ฐ ํ† ํฌ๋‚˜์ด์ €๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
6
- model_name = "t5-base"
7
- model = T5ForConditionalGeneration.from_pretrained(model_name)
8
- tokenizer = T5Tokenizer.from_pretrained(model_name)
 
9
 
10
- def generate_question(prompt):
11
- # ์ฃผ์–ด์ง„ ์ž…๋ ฅ์— ๊ธฐ๋ฐ˜ํ•˜์—ฌ ํ€ด์ฆˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
12
- input_text = f"ํ€ด์ฆˆ: {prompt} ๋Œ€๋‹ต:"
13
- input_ids = tokenizer.encode(input_text, return_tensors="pt")
14
-
15
- # ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ€ด์ฆˆ ์ƒ์„ฑ
16
- output = model.generate(input_ids)
17
- question = tokenizer.decode(output[0], skip_special_tokens=True)
18
-
19
- return question
20
-
21
- # Gradio๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›น ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
22
  iface = gr.Interface(
23
- fn=generate_question,
24
- inputs="text",
25
  outputs="text",
26
  live=True,
27
- interpretation="default"
28
  )
29
 
30
- # ์›น ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
31
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
 
3
 
4
+ # Hugging Face ๋ชจ๋ธ ๋กœ๋“œ
5
+ model_name = "distilbert-base-cased-distilled-squad"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
8
+ qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
9
 
10
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
 
 
 
 
 
 
 
 
 
 
 
11
  iface = gr.Interface(
12
+ fn=lambda question: qa_pipeline(question=question, context=context)["answer"],
13
+ inputs=gr.Textbox(prompt="Enter a question"),
14
  outputs="text",
15
  live=True,
16
+ capture_session=True,
17
  )
18
 
19
+ # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
20
  iface.launch()