-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate AI functionality to free Pollinations AI #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+205
−69
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/sayanthrock/freeairock/data/ai/PollinationsApiService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.sayanthrock.freeairock.data.ai | ||
|
|
||
| import retrofit2.http.Body | ||
| import retrofit2.http.POST | ||
|
|
||
| data class PollinationsMessage( | ||
| val role: String, | ||
| val content: String | ||
| ) | ||
|
|
||
| data class PollinationsRequest( | ||
| val messages: List<PollinationsMessage>, | ||
| val model: String? = null | ||
| ) | ||
|
|
||
| interface PollinationsApiService { | ||
| @POST("/") | ||
| suspend fun generateText( | ||
| @Body request: PollinationsRequest | ||
| ): String | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
app/src/main/java/com/sayanthrock/freeairock/ui/ImageStudioScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package com.sayanthrock.freeairock.ui | ||
|
|
||
| import android.net.Uri | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.OutlinedTextField | ||
| import androidx.compose.material3.Surface | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.collectAsState | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.text.font.FontFamily | ||
| import androidx.compose.ui.unit.dp | ||
| import coil.compose.AsyncImage | ||
| import coil.compose.SubcomposeAsyncImage | ||
| import com.sayanthrock.freeairock.data.image.BitmapImageState | ||
|
|
||
| @Composable | ||
| fun ImageStudioScreen( | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| var prompt by remember { mutableStateOf("") } | ||
| var imageUrl by remember { mutableStateOf<String?>(null) } | ||
| var isGenerating by remember { mutableStateOf(false) } | ||
|
SayanthRock marked this conversation as resolved.
|
||
|
|
||
| Column( | ||
| modifier = modifier | ||
| .fillMaxSize() | ||
| .padding(24.dp) | ||
| .verticalScroll(rememberScrollState()), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| Text( | ||
| text = "Image Studio", | ||
| style = MaterialTheme.typography.headlineMedium, | ||
| fontFamily = FontFamily.Monospace, | ||
| color = MaterialTheme.colorScheme.primary, | ||
| modifier = Modifier.align(Alignment.Start) | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(24.dp)) | ||
|
|
||
| OutlinedTextField( | ||
| value = prompt, | ||
| onValueChange = { prompt = it }, | ||
| label = { Text("Describe the image you want") }, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| singleLine = false, | ||
| maxLines = 5 | ||
| ) | ||
|
|
||
| Spacer(modifier = Modifier.height(16.dp)) | ||
|
|
||
| Button( | ||
| onClick = { | ||
| if (prompt.isNotBlank()) { | ||
| val seed = (0..1000000).random() | ||
| imageUrl = "https://image.pollinations.ai/prompt/${Uri.encode(prompt)}?seed=$seed" | ||
| isGenerating = true | ||
| } | ||
| }, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| enabled = prompt.isNotBlank() && !isGenerating | ||
| ) { | ||
| Text(if (isGenerating) "Generating..." else "Generate Image") | ||
| } | ||
|
|
||
| Spacer(modifier = Modifier.height(32.dp)) | ||
|
|
||
| imageUrl?.let { url -> | ||
| Surface( | ||
| color = MaterialTheme.colorScheme.surface, | ||
| shape = MaterialTheme.shapes.medium, | ||
| modifier = Modifier.fillMaxWidth().height(300.dp) | ||
| ) { | ||
| SubcomposeAsyncImage( | ||
| model = url, | ||
| contentDescription = "Generated Image", | ||
| loading = { | ||
| Column( | ||
| verticalArrangement = Arrangement.Center, | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| modifier = Modifier.fillMaxSize() | ||
| ) { | ||
| CircularProgressIndicator() | ||
| } | ||
| }, | ||
| onSuccess = { | ||
| isGenerating = false | ||
| }, | ||
| onError = { | ||
| isGenerating = false | ||
| }, | ||
|
SayanthRock marked this conversation as resolved.
SayanthRock marked this conversation as resolved.
|
||
| contentScale = ContentScale.Fit, | ||
| modifier = Modifier.fillMaxSize() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.