CoolFace
Apppublic

Sincon0121/literary-recommender

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py27 linesDownload Raw Back to root
1import gradio as gr
2from transformers import pipeline
3
4generator = pipeline("text-generation", 
5                     model="mistralai/Mistral-7B-Instruct-v0.2", 
6                     max_new_tokens=256, 
7                     do_sample=True, 
8                     temperature=0.7)
9
10def recommend_book(description):
11    prompt = f"""
12    문학 작품에 대한 아래 설명을 바탕으로, 그와 비슷한 분위기나 주제를 가진 문학 작품을 한 권 추천해줘. 제목과 간단한 이유도 함께 설명해줘.
13
14    설명: {description}
15    """
16    response = generator(prompt)[0]["generated_text"]
17    return response.strip()
18
19interface = gr.Interface(
20    fn=recommend_book,
21    inputs=gr.Textbox(label="작품 설명을 입력하세요", lines=5),
22    outputs=gr.Textbox(label="추천 작품"),
23    title="문학 작품 추천 챗봇",
24    description="작품 설명을 입력하면 비슷한 분위기의 다음 도서를 추천해줍니다."
25)
26
27interface.launch()