Spaces:
Sleeping
Sleeping
Commit
·
45f1dc9
0
Parent(s):
Initial Space setup
Browse files- README.md +33 -0
- app.py +62 -0
- requirements.txt +4 -0
README.md
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# DeepSeek Tweet Generator Space
|
2 |
+
|
3 |
+
This Space hosts a DeepSeek model fine-tuned for generating tweets based on a given style profile and recent tweet examples.
|
4 |
+
|
5 |
+
## Usage
|
6 |
+
|
7 |
+
The interface accepts three inputs:
|
8 |
+
|
9 |
+
1. **Style Profile** (JSON): A JSON object containing style characteristics like tone, complexity, and technical level
|
10 |
+
2. **Recent Tweets**: Example tweets to base the style on
|
11 |
+
3. **Topic**: The topic to generate a tweet about
|
12 |
+
|
13 |
+
Example Style Profile:
|
14 |
+
```json
|
15 |
+
{
|
16 |
+
"tone": "Natural",
|
17 |
+
"complexity": 2.8,
|
18 |
+
"technical_level": "Technical"
|
19 |
+
}
|
20 |
+
```
|
21 |
+
|
22 |
+
## Model Details
|
23 |
+
|
24 |
+
- Base Model: deepseek-ai/deepseek-coder-6.7b-base
|
25 |
+
- Modifications: Optimized for tweet generation while maintaining technical accuracy
|
26 |
+
- Max Length: 280 characters (Twitter limit)
|
27 |
+
|
28 |
+
## Environment
|
29 |
+
|
30 |
+
- Python 3.9+
|
31 |
+
- PyTorch 2.1.2
|
32 |
+
- Transformers 4.36.2
|
33 |
+
- Gradio 4.12.0
|
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Initialize model and tokenizer
|
6 |
+
model_name = "deepseek-ai/deepseek-coder-6.7b-base"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
9 |
+
model_name,
|
10 |
+
torch_dtype=torch.float16,
|
11 |
+
device_map="auto",
|
12 |
+
trust_remote_code=True
|
13 |
+
)
|
14 |
+
|
15 |
+
def generate_tweet(prompt, max_length=280, temperature=0.7, top_p=0.95):
|
16 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
17 |
+
|
18 |
+
outputs = model.generate(
|
19 |
+
**inputs,
|
20 |
+
max_new_tokens=max_length,
|
21 |
+
temperature=temperature,
|
22 |
+
top_p=top_p,
|
23 |
+
do_sample=True,
|
24 |
+
pad_token_id=tokenizer.eos_token_id
|
25 |
+
)
|
26 |
+
|
27 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
28 |
+
|
29 |
+
def process_request(style_profile, recent_tweets, topic):
|
30 |
+
prompt = f"""Generate a tweet about "{topic}" that matches the following style:
|
31 |
+
|
32 |
+
Style Characteristics:
|
33 |
+
- Tone: {style_profile.get('tone', 'Natural')}
|
34 |
+
- Complexity: {style_profile.get('complexity', '2.8')}
|
35 |
+
- Technical Level: {style_profile.get('technical_level', 'Technical')}
|
36 |
+
|
37 |
+
Recent tweet examples for style reference:
|
38 |
+
{recent_tweets}
|
39 |
+
|
40 |
+
Technical Context:
|
41 |
+
Based on rushimanche's expertise and recent discussions
|
42 |
+
|
43 |
+
Generate a single tweet (max 280 characters) that matches this style and discusses the given topic.
|
44 |
+
Response format: Just the tweet text, no additional commentary."""
|
45 |
+
|
46 |
+
return generate_tweet(prompt)
|
47 |
+
|
48 |
+
# Create Gradio interface
|
49 |
+
iface = gr.Interface(
|
50 |
+
fn=process_request,
|
51 |
+
inputs=[
|
52 |
+
gr.JSON(label="Style Profile"),
|
53 |
+
gr.Textbox(label="Recent Tweets", lines=5),
|
54 |
+
gr.Textbox(label="Topic")
|
55 |
+
],
|
56 |
+
outputs=gr.Textbox(label="Generated Tweet"),
|
57 |
+
title="DeepSeek Tweet Generator",
|
58 |
+
description="Generate tweets using DeepSeek model based on style profile and recent tweets"
|
59 |
+
)
|
60 |
+
|
61 |
+
# Launch the interface
|
62 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.12.0
|
2 |
+
torch==2.1.2
|
3 |
+
transformers==4.36.2
|
4 |
+
accelerate==0.25.0
|