Sharyar
commited on
Commit
·
cbe35fe
1
Parent(s):
092b44e
Feat: Re-initialize with stable zero-shot Inference API project
Browse files- .gitignore +17 -0
- LICENSE +21 -0
- README.md +59 -0
- app.py +118 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# Environment
|
| 7 |
+
.env
|
| 8 |
+
.venv
|
| 9 |
+
venv/
|
| 10 |
+
env/
|
| 11 |
+
|
| 12 |
+
# IDEs
|
| 13 |
+
.vscode/
|
| 14 |
+
.idea/
|
| 15 |
+
|
| 16 |
+
# macOS
|
| 17 |
+
.DS_Store
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Technical Description Assistant
|
| 3 |
+
emoji: 📝
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.29.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Technical Description Assistant
|
| 14 |
+
|
| 15 |
+
A simple, zero-shot Hugging Face Space that helps developers instantly rewrite
|
| 16 |
+
rough project descriptions into clean, professional technical summaries.
|
| 17 |
+
|
| 18 |
+
## How It Works
|
| 19 |
+
|
| 20 |
+
This application uses the Hugging Face Inference API to call a powerful,
|
| 21 |
+
pre-trained large language model (`mistralai/Mistral-7B-Instruct-v0.2`).
|
| 22 |
+
It requires no local model download, making the application lightweight and fast to deploy.
|
| 23 |
+
|
| 24 |
+
1. **Input**: A developer enters a casual or rough description of their project.
|
| 25 |
+
2. **Processing**: The description is sent to the model with a carefully crafted system prompt that instructs it to act as an expert technical writer.
|
| 26 |
+
3. **Output**: The model returns a polished, professional, and technically accurate summary.
|
| 27 |
+
|
| 28 |
+
## Tech Stack
|
| 29 |
+
|
| 30 |
+
- **UI**: Gradio
|
| 31 |
+
- **Model API**: `huggingface_hub.InferenceClient`
|
| 32 |
+
- **Language Model**: `mistralai/Mistral-7B-Instruct-v0.2` (zero-shot)
|
| 33 |
+
- **Hosting**: Hugging Face Spaces
|
| 34 |
+
|
| 35 |
+
## Running Locally
|
| 36 |
+
|
| 37 |
+
To run this project on your own machine:
|
| 38 |
+
|
| 39 |
+
1. **Clone the repository:**
|
| 40 |
+
```bash
|
| 41 |
+
git clone https://huggingface.co/spaces/Snaseem2026/technical-description-assistant
|
| 42 |
+
cd technical-description-assistant
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
2. **Install dependencies:**
|
| 46 |
+
```bash
|
| 47 |
+
pip install -r requirements.txt
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
3. **Set your Hugging Face token (optional but recommended):**
|
| 51 |
+
For full access to the Inference API, set your token as an environment variable.
|
| 52 |
+
```bash
|
| 53 |
+
export HUGGING_FACE_HUB_TOKEN="hf_YOUR_TOKEN_HERE"
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
4. **Run the application:**
|
| 57 |
+
```bash
|
| 58 |
+
python app.py
|
| 59 |
+
```
|
app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Use a reliable zero-shot model from the Hugging Face Inference API
|
| 6 |
+
MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.2"
|
| 7 |
+
|
| 8 |
+
# It's recommended to set your Hugging Face token as an environment variable
|
| 9 |
+
# For local testing, you can also pass it directly: client = InferenceClient(token="hf_...")
|
| 10 |
+
client = InferenceClient(model=MODEL_ID)
|
| 11 |
+
|
| 12 |
+
SYSTEM_PROMPT = """
|
| 13 |
+
You are an expert AI assistant that rewrites software project descriptions.
|
| 14 |
+
Your task is to convert a developer's informal, rough notes into a clear,
|
| 15 |
+
concise, and professional technical summary.
|
| 16 |
+
|
| 17 |
+
Key guidelines:
|
| 18 |
+
- Preserve all core technical details and technologies mentioned.
|
| 19 |
+
- Adopt a neutral, professional, and informative tone.
|
| 20 |
+
- Correct grammar and improve the overall structure and clarity.
|
| 21 |
+
- Aim for a length of 2 to 4 well-structured sentences.
|
| 22 |
+
- Do not repeat the original input. Focus only on the improved version.
|
| 23 |
+
""".strip()
|
| 24 |
+
|
| 25 |
+
def improve_description(user_input: str) -> str:
|
| 26 |
+
"""
|
| 27 |
+
Rewrites a rough project description into a professional, technical summary
|
| 28 |
+
using a zero-shot large language model.
|
| 29 |
+
"""
|
| 30 |
+
if not user_input or not user_input.strip():
|
| 31 |
+
return "Please provide a description to improve."
|
| 32 |
+
|
| 33 |
+
user_text = user_input.strip()
|
| 34 |
+
if len(user_text) < 10:
|
| 35 |
+
return "The description is too short. Please add more details about your project."
|
| 36 |
+
|
| 37 |
+
# Construct the prompt for the model
|
| 38 |
+
messages = [
|
| 39 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 40 |
+
{
|
| 41 |
+
"role": "user",
|
| 42 |
+
"content": (
|
| 43 |
+
"Please rewrite the following project description into a professional "
|
| 44 |
+
"and technical summary, following all system guidelines.\n\n"
|
| 45 |
+
f"Original Description:\n'{user_text}'"
|
| 46 |
+
),
|
| 47 |
+
},
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
# Call the Inference API
|
| 52 |
+
response = client.chat_completion(
|
| 53 |
+
messages=messages,
|
| 54 |
+
max_tokens=300,
|
| 55 |
+
temperature=0.2, # Lower temperature for more focused and professional output
|
| 56 |
+
top_p=0.9,
|
| 57 |
+
)
|
| 58 |
+
improved_text = response.choices[0].message.content.strip()
|
| 59 |
+
|
| 60 |
+
# Final check to prevent returning the original text
|
| 61 |
+
if improved_text.lower() == user_text.lower():
|
| 62 |
+
return "Could not generate a meaningful improvement. Please try rephrasing or adding more detail."
|
| 63 |
+
|
| 64 |
+
return improved_text
|
| 65 |
+
except Exception as e:
|
| 66 |
+
# Provide a helpful error message if the API call fails
|
| 67 |
+
error_message = f"An error occurred with the model service: {e}"
|
| 68 |
+
print(error_message)
|
| 69 |
+
return "Sorry, the AI model service is currently unavailable. Please try again later."
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# --- Gradio Interface ---
|
| 73 |
+
with gr.Blocks(title="Technical Description Assistant", theme=gr.themes.Soft()) as demo:
|
| 74 |
+
gr.Markdown(
|
| 75 |
+
"""
|
| 76 |
+
# 📝 Technical Description Assistant
|
| 77 |
+
Instantly transform your rough project notes into a polished, professional
|
| 78 |
+
technical description using a zero-shot AI model.
|
| 79 |
+
"""
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
with gr.Row():
|
| 83 |
+
input_text = gr.Textbox(
|
| 84 |
+
label="Your Rough Description",
|
| 85 |
+
placeholder="e.g., 'my app uses python and ml stuff to make pics look better'",
|
| 86 |
+
lines=10,
|
| 87 |
+
scale=1,
|
| 88 |
+
)
|
| 89 |
+
output_text = gr.Textbox(
|
| 90 |
+
label="Polished Technical Description",
|
| 91 |
+
lines=10,
|
| 92 |
+
scale=1,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
submit_btn = gr.Button("✨ Generate Polished Description", variant="primary")
|
| 96 |
+
|
| 97 |
+
gr.Markdown("### A few examples to get you started:")
|
| 98 |
+
gr.Examples(
|
| 99 |
+
examples=[
|
| 100 |
+
"This is a web app that lets users upload pics and it uses AI to make them look better. Built with Python and some ML stuff.",
|
| 101 |
+
"Made a tool that checks code for bugs. It's really fast and works with multiple languages. Uses AST parsing.",
|
| 102 |
+
"API for weather data. Gets info from multiple sources and combines them. Has caching so it's faster.",
|
| 103 |
+
"This project uses docker and cloud stuff to run machines.",
|
| 104 |
+
],
|
| 105 |
+
inputs=input_text,
|
| 106 |
+
outputs=output_text,
|
| 107 |
+
fn=improve_description,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
submit_btn.click(
|
| 111 |
+
fn=improve_description,
|
| 112 |
+
inputs=input_text,
|
| 113 |
+
outputs=output_text,
|
| 114 |
+
api_name="improve_description"
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Pinning versions that are known to be compatible and stable on Hugging Face Spaces.
|
| 2 |
+
gradio==4.29.0
|
| 3 |
+
huggingface_hub==0.22.2
|