File size: 4,122 Bytes
d208a7c
 
 
 
 
 
 
 
 
 
 
f66e2c9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
title: StyleForge Lite
emoji: 🔬
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: "4.44.0"
app_file: app.py
pinned: false
---

# 🔬 StyleForge Lite

A minimal Gradio app that learns your scientific writing style from pasted abstracts and rewrites new text in that style using the Groq API.

## Features

- **Style Learning**: Paste 3-8 abstracts to build your writing profile
- **Text Rewriting**: Rewrite any text in your learned scientific style
- **Style Metrics**: Get detailed scoring on:
  - Average sentence length
  - Passive voice ratio
  - Vocabulary match (% scientific verbs)
  - Flow markers (context→method→result→implication)
  - Total score (/20)
- **Deployment Guide**: Built-in instructions for Hugging Face Spaces

## Quick Deploy to Hugging Face Spaces

### Method 1: Direct Clone (Recommended)

1. **Clone this repository**:
   ```bash
   git clone https://huggingface.co/spaces/Babajaan/Writing-Style
   cd Writing-Style
   ```

2. **Set your API key**:
   - Go to your Space settings
   - Add `GROQ_API_KEY` as a secret with your Groq API key
   - Get your API key from [Groq Console](https://console.groq.com)

3. **Deploy**: The Space will automatically rebuild with your changes

### Method 2: Create New Space

1. **Create new Space**:
   - Go to [Hugging Face Spaces](https://huggingface.co/spaces)
   - Click "Create new Space"
   - Choose "Gradio" as SDK
   - Set visibility (Public/Private)

2. **Upload files**:
   - Upload `app.py`
   - Upload `requirements.txt`
   - Upload this `README.md`

3. **Configure environment**:
   - Add `GROQ_API_KEY` in Space settings → Secrets
   - Set Space hardware (CPU is sufficient)

4. **Deploy**: The Space will automatically build and deploy

## Environment Variables

- `GROQ_API_KEY`: Your Groq API key (required)

## Requirements

- Python 3.8+
- Gradio >= 4.44.0
- Groq >= 0.9.0

## Usage

1. **Paste Abstracts**: Input 3-8 of your scientific abstracts in the first text box
2. **Enter Text**: Input the text you want to rewrite in the second text box
3. **Click "Build Profile & Rewrite"**: The app will analyze your style and rewrite the text
4. **View Results**: See the rewritten text and style metrics

## Style Analysis

The app analyzes your writing style based on:

- **Sentence Length**: Optimal 15-25 words per sentence
- **Voice**: Preference for active over passive voice
- **Vocabulary**: Use of precise scientific verbs (identify, demonstrate, suggest, etc.)
- **Flow**: Logical progression from context → method → result → implication

## Troubleshooting

- **Build fails**: Check `requirements.txt` syntax
- **API errors**: Verify `GROQ_API_KEY` is set correctly in Space secrets
- **Import errors**: Ensure all dependencies are in `requirements.txt`
- **Empty responses**: Check your Groq API key and quota

## Cost Considerations

- Groq API has generous free tier
- Monitor usage in [Groq Console](https://console.groq.com)
- Consider rate limiting for production use

## Example

**Input Abstracts**:
```
Resveratrol (RESL), a natural polyphenol, has been studied for its cancer chemopreventive properties. In this study, a diacetate derivative (RESL43) was synthesized, exhibiting potent cytotoxic and pro-apoptotic effects in U937 cells. Molecular docking indicated that RESL43 may inhibit NFκB by disrupting DNA–protein interactions. These findings support stronger activity than RESL and warrant further investigation.
```

**Original Text**:
```
Our study shows that the new drug works well. We tested it on cells and found good results. The drug might help treat cancer.
```

**Rewritten Output**:
```
Our investigation demonstrates that the novel therapeutic compound exhibits significant efficacy in cellular models. Through comprehensive in vitro analysis, we identified substantial cytotoxic activity and pro-apoptotic effects in U937 cell lines. These findings suggest the potential utility of this compound as a chemopreventive agent and warrant further investigation into its molecular mechanisms.
```

## License

This project is open source and available under the MIT License.