King-8 commited on
Commit
e68852a
·
verified ·
1 Parent(s): ccb12dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -27
app.py CHANGED
@@ -1,32 +1,20 @@
1
- from huggingface_hub import InferenceClient
2
  import gradio as gr
 
3
 
4
- # Load your fine-tuned model
5
- client = InferenceClient("King-8/community-gpt2")
6
 
7
- # Simple function to chat
8
- def chat_fn(message, history):
9
- # Merge history into the prompt
10
- history_text = ""
11
- for user_input, model_output in history:
12
- history_text += f"User: {user_input}\nAssistant: {model_output}\n"
13
- full_prompt = history_text + f"User: {message}\nAssistant:"
14
 
15
- # Generate a response
16
- response = client.text_generation(
17
- prompt=full_prompt,
18
- max_new_tokens=100,
19
- temperature=0.7,
20
- repetition_penalty=1.1,
21
- )
22
 
23
- # Add the new interaction to history
24
- history.append((message, response))
25
- return history
26
-
27
- # Set up the Gradio app
28
- gr.ChatInterface(
29
- fn=chat_fn,
30
- title="Community Chatbot",
31
- description="A chatbot fine-tuned on community conversations using GPT-2.",
32
- ).launch()
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load the text-generation pipeline
5
+ generator = pipeline("text-generation", model="King-8/community-gpt2")
6
 
7
+ # Define the chatbot response function
8
+ def chat(prompt):
9
+ response = generator(prompt, max_length=100, do_sample=True, temperature=0.7)
10
+ return response[0]["generated_text"]
 
 
 
11
 
12
+ # Set up the Gradio interface
13
+ iface = gr.Interface(fn=chat,
14
+ inputs="text",
15
+ outputs="text",
16
+ title="Community GPT-2 Chatbot",
17
+ description="Ask me anything!")
 
18
 
19
+ # Launch the app
20
+ iface.launch()